ROBOTI
문제
In the computer game Robots, the player tries to escape mad robots. There are many robots against the lone player, but their movement is predictable and the player can take advantage of that.
The game is played on a board of size R×C. The following 5 steps are repeated:
- The player moves in one of eight directions (horizontally, vertically or diagonally) or stays in the same cell.
- If the player moves to a cell occupied by a robot, the game ends and the player loses.
- Every robot moves in one of eight directions, to the neighbouring cell closest to the player. More precisely, the robot attempts to minimize the value of |r1−r2| + |s1−s2|, where (r1, s1) and (r2, s2) are the positions of the player and robot.
- If any robot has entered the player's cell, the game ends and the player loses.
- If two or more robots have entered the same cell, a large explosion destroys all the robots in that cell.
You will be given the starting location of the player, the locations of all robots and the moves the player makes. If the player makes all his moves and survives, you are to output the state of the board after all his moves. Otherwise, output how many moves he was able to make.
입력
The first line of input contains two integers R and C (1 ≤ R ≤ 100, 1 ≤ S ≤ 100), the number of rows and columns on the board.
The following R lines contain C characters each, depicting the initial state on the board: the character '.' denotes an empty cell, 'R' a cell occupied by a robot, and 'I' the cell with the player.
The final line contains a string of at most 100 digits, the player's moves. Each move is a digit from 1 to 9, 5 meaning the player does not move, the rest according to this diagram:
[이미지 1]
The input sequence of moves will be such that the player will never attempt to move outside the board.
출력
If the player makes all the moves and survives, output the final state of the board in the same format as in the output. Otherwise, output "kraj X" (quotes for clarity), where X is the number of moves the player made.
힌트
In the second example, the three robots on the left side of the map crash after the player opts to stand still in his first move. After the third move, the two robots from the right side of the map crash, while the robot from the bottom of the map pursues the player once he starts to move upwards.
예제
예제 1
4 5 I.... ..... .R.R. ..... 6
.I... .RR.. ..... .....
예제 2
9 10 .......... .........R .......... R......... R...I..... R......... .......... .........R ....R..... 5558888
....I..... ....R..... .......... .......... .......... .......... .......... .......... ..........
예제 3
12 8 ...I.... ........ ........ ........ ........ RR...... ......RR R......R ........ ........ ........ ...R.... 66445394444162
kraj 11