Crazy Arduino
Time limit1sMemory limit128 MB
Simulate Jongsu's moves and the chasing robots on the R by C board, and report the final board or the move where he is caught.
- Level
Medium4 of 10
- Topics
- Simulation, Implementation
- Solved
- No attempts yet
Problem
Jongsu built a game called "Robots" using an Arduino. Jongsu controls a single Arduino and must keep dodging the crazy Arduinos that chase him. A crazy Arduino keeps closing in on Jongsu's Arduino, but its movement is completely predictable.
The game is played on an board, and one turn consists of the following five steps. The turn is repeated as many times as the length of the given move string.
- First, Jongsu moves his Arduino one cell in one of the 8 directions (horizontal, vertical, or diagonal), or leaves it in place.
- If Jongsu's Arduino moves onto a cell that holds a crazy Arduino, the game ends and Jongsu loses.
- Each crazy Arduino moves one cell in the direction that brings it closest to Jongsu's Arduino. If Jongsu is at and the crazy Arduino is at , it picks the move that minimizes afterward.
- If a crazy Arduino moves onto the cell holding Jongsu's Arduino, the game ends and Jongsu loses.
- If two or more distinct crazy Arduinos end up on the same cell, a large explosion occurs and every crazy Arduino on that cell is destroyed.
You are given Jongsu's starting position, the positions of the crazy Arduinos, and the direction Jongsu tries to move on each turn. Determine the final state of the board after Jongsu moves as directed. If the game ends partway through, determine on which move it ends.
Input
The first line contains the board size and . ()
Each of the next lines contains characters describing the board. . is an empty cell, R is a crazy Arduino, and I is Jongsu's Arduino.
The last line contains a string of length at most giving, in order, the direction Jongsu tries to move on each turn. Directions follow the layout of a numeric keypad. 5 means staying in place, and the other digits mean the directions below. "Up" is the direction in which the row number decreases.
7 = ↖ 8 = ↑ 9 = ↗
4 = ← 5 = stay 6 = →
1 = ↙ 2 = ↓ 3 = ↘

No input makes Jongsu move off the board.
Output
If the game ends partway through, print kraj X. is the number of moves Jongsu attempts, counting the turn on which the game ends. That is, if the game ends while processing the -th direction, then is .
If the game does not end before every direction is processed, print the final state of the board in the same format as the input.