問題一覧 > 通常問題

No.331 Do It with CodeRunner

レベル : / AI推定難易度 : 975 / 実行時間制限 : 1ケース 5.000秒 / メモリ制限 : 512 MB / リアクティブ問題 (詳しくはこちら)
タグ : (AC するまで非表示) / 解いたユーザー数 47
作問者 : uwi
お気に入りにしたユーザー ProblemId : 877 / 自分の提出
問題文最終更新日: 2026-06-25 05:58:23
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.
The actions you can take are as follows.
  • 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.
In the initial state and after each action, you can learn the following values.
  • How many cells you can advance from the current position in the current direction
  • Whether you have reached the goal
Repeat actions starting from the initial position until you reach 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$.
For example, in the following 5*4 maze, where walls are represented by "#", empty cells by ".", and the current position by "v", if you are facing down, the number of cells you can advance is 2.
####
#.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
These correspond to the following actions.
  • 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もしくは右上の雲マークをクリックしてアカウントを作成してください。