RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
COCI00340

Zmija

Unrated 레이팅 미적용
난이도
1s
시간 제한
32MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

\(5^{th}\) round, January \(17^{th}\) 2015
Mirko is making a clone of the popular computer game "Snake". In the game, you control the movement
of a snake on a screen with dimensions of \(R \cdot S\) pixels. The objective of the game is to collect all the
apples.
Unfortunately, Mirko’s implementation isn’t that great and the gameplay is different than the original.
Here is a description of Mirko’s game:
• unlike the original, the apples don’t appear randomly on the screen, but instead you know the
positions of all apples at the beginning of the game
• at the beginning of the game, the snake is located in the lower left pixel of the screen and is
facing right
• there are two buttons in the game, denoted with A and B
• when you press the button A, the snake moves forward by 1 pixel in the direction which it is
currently facing. If that move would cause the snake to go offscreen, nothing happens.
• when you press the button B, the snake moves up by 1 pixel and changes the direction it’s facing
by 180°
• when the snake moves to a pixel containing an apple, it eats the apple but doesn’t grow like in
the original game
You have the following task: for given positions of apples at the beginning of the game, determine the
smallest number of button presses it takes for the snake to collect all the apples.

제약
입력 형식

The first line of input contains the integers \(R\) and \(S\) (2 ⩽R, S ⩽1 000), the height and width of the
screen.
Each of the following \(R\) lines contains exactly \(S\) characters. These characters represent the content of
the screen. Pixels with apples on them are denoted with ’J’ and empty pixels are denoted with ’.’.
The lower left corner contains the character ’Z’ that represents the snake in its initial position.

출력 형식

The first and only line of output must contain the required minimal number of button presses.

예제 1
입력
5 5
...J.
.....
J..J.
J....
Z....
5 5
.....
J...J
.J.J.
.JJJ.
Z....
3 4
...J
....
Z...
출력
output
output
7
15
5
설명

Clarification of the first example: The shortest sequence of button presses needed for the snake to collect
all the apples is BBAAABB.

문제 정보

생성자가 기록되지 않았습니다.

출처 COCI 2014/2015 Contest 5

평가 및 의견

Zmija

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Zmija

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8