ROBOTI | 프로그래밍의 벗 PivotOJ
PivotOJ

ROBOTI

시간 제한: 1000ms메모리 제한: 128MB출처: CHC 2009 Regional Competition - JuniorsBOJ 8972
이 문제는 본문 이미지 일부가 표시되지 않습니다. 텍스트만으로 풀이가 어려울 수 있습니다.

문제

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: 

  1. The player moves in one of eight directions (horizontally, vertically or diagonally) or stays in the same cell. 
  2. If the player moves to a cell occupied by a robot, the game ends and the player loses. 
  3. 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. 
  4. If any robot has entered the player's cell, the game ends and the player loses. 
  5. 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
코드를 제출하려면 로그인하세요.