No.331 Do It with CodeRunner
問題文最終更新日: 2026-06-25 05:58:23
English (AI translation)
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence.
Back to the original
Advent Calendar Contest 2015
(順位表)
の他の問題:
Problem Statement
You are somewhere in a maze, facing up, down, left, or right. The following is known about the maze.
- The maze is a rectangular grid.
- The outside of the maze consists of empty cells.
- The maze consists only of walls and empty cells.
- The goal cell is one empty cell on the perimeter of the maze that is not a corner.
- All cells on the perimeter of the maze other than the goal are walls.
- You cannot enter wall cells.
- The goal can always be reached from the initial position by moving only through adjacent empty cells.
- The initial position is an empty cell that is not the goal.
- F : Move forward by exactly 1 cell from the current position in the current direction. If you cannot move forward, you stay where you are.
- B : Move backward by exactly 1 cell from the current position relative to the current direction. Your direction does not change. If you cannot move backward, you stay where you are.
- L : Rotate your direction 90 degrees counterclockwise without changing your position.
- R : Rotate your direction 90 degrees clockwise without changing your position.
- How many cells you can advance from the current position in the current direction
- Whether you have reached the goal
This problem is reactive.
入力 → 出力 → 入力 → 出力 → ... → 入力("Merry Christmas!") → 終了
The interaction proceeds as shown above. Both input and output are done one line per step.
Input
The input line is determined by the following logic. It ends with a newline.- If the current position is the goal, "Merry Christmas!".
- Otherwise, the number of cells you can advance from the current position in the current direction. If you can advance infinitely, $20151224$.
#### #.v# #..# #... ####
The maze and the initial position are guaranteed to satisfy all the conditions listed at the beginning of the problem statement.
The size of the maze is not given, but if the vertical size is N and the horizontal size is M, then
$3\le N\le 20,$
$3\le M\le 20$
are satisfied.
Output
The output must be one of the following. After each output, be sure to print a newline and flush. Also, if "Merry Christmas!" is given as input, you have arrived at the goal, so terminate your program.
- F
- B
- L
- R
- F : Move forward by exactly 1 cell from the current position in the current direction. If you cannot move forward, you stay where you are.
- B : Move backward by exactly 1 cell from the current position relative to the current direction. Your direction does not change. If you cannot move backward, you stay where you are.
- L : Rotate your direction 90 degrees counterclockwise without changing your position.
- R : Rotate your direction 90 degrees clockwise without changing your position.
Sample
The following shows an example of the process of reaching the goal in the maze above.
| Input | Output | State |
|---|---|---|
| 2 |
#### #.v# #..# #... #### |
|
| F | ||
| 1 |
#### #..# #.v# #... #### |
|
| F | ||
| 0 |
#### #..# #..# #.v. #### |
|
| L | ||
| 20151224 |
#### #..# #..# #.>. #### |
|
| B | ||
| 20151224 |
#### #..# #..# #>.. #### |
|
| F | ||
| 20151224 |
#### #..# #..# #.>. #### |
|
| F | ||
| Merry Christmas! |
#### #..# #..# #..> #### |
Note
The writer's simple program (Java,Scanner) seems to get TLE at around 10000 steps. With C++, around 30000 to 40000 steps seems feasible.提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。