IOI '03 - Kenosha, Wisconsin, USA
You are the proud owner of two robots that are located in separate
rectangular mazes. Square
At the beginning of each minute, you broadcast the same command to both robots. Each command is a direction (north, south, east, or west). A robot moves one square in the direction of the command, unless the robot would collide with a wall, in which case the robot does not move for that minute. A robot exits the maze by walking out of it. A robot ignores commands after it has exited its maze.
Guards move one square at the beginning of each minute, at the same time as the robots. Each guard begins at a given square facing a given direction and moves forward one square per minute until the guard has moved one fewer square than the number of squares in his patrol path. The guard then turns around instantaneously and walks in the opposite direction back to his starting square, where he turns around again and repeats his patrol path until each robot has exited its maze.
A guard's patrol will not require the guard to walk through walls or exit the maze. Although guard patrols may overlap, no two guards will ever collide: they will never occupy the same square at the end of a minute, and they will not exchange squares with each other during a minute. A guard in a maze will not start in the same square as the robot in that maze.
A guard captures a robot if the guard occupies the same square at the end of a minute as the robot, or if the guard and the robot exchange squares with each other during a minute.
Given two mazes (each no larger than
Input Specification
The first set of lines describes the first maze and its occupants. Subsequently, the second set of lines describes the second maze and its occupants.
- The first line of input contains two space-separated integers,
and , the number of rows and columns in maze . - The next
lines each contain characters specifying the maze layout. The robot's starting square is specified by anX
. A.
represents an open space and#
represents a wall. Each maze will contain exactly one robot. - Following the maze layout is a single line with a single integer
, the number of guards in the first maze . - Each of the next
lines describes a guard's patrol as three integers and a character, separated by single spaces. The first two integers specify the row and column of the starting square of the guard. The third integer specifies the number of squares in the guard's patrol path. The character specifies the initial direction the guard is facing:N
,S
,E
, orW
(north, south, east, and west, respectively).
The description of the second maze follows the description of the first, in the same format but with potentially different values.
Output Specification
The first line of the output should contain a single integer N
, S
, E
, W
-1
.
Both robots should exit their mazes by the end of the commands. The last command should cause at least one of the robots to exit its maze. If multiple sequences of commands cause the robots to exit in the minimum time, any will be accepted.
Sample Input
5 4
####
#X.#
#..#
...#
##.#
1
4 3 2 W
4 4
####
#...
#X.#
####
0
Sample Output
8
E
N
E
S
S
S
E
S
Diagram
Scoring
No partial credit will be given on test cases for which no sequence of commands exists. Partial credit for other test cases will be given as described below.
Correctness:
The output file for a test case is considered correct if it is correctly
formatted, contains no more than
Minimality:
The output file for a test case is considered minimal if it is correct and there is no shorter sequence of commands that is correct. A program whose sequence of commands is not minimal will receive no points for minimality.
Comments