INK
Time limit1sMemory limit1024 MB
Simulate a square on an N by N grid that moves, stores ink, and jumps to dye obstacles within Manhattan distance, then print the final grid.
- Level
Easy3 of 10
- Topics
- Simulation, Implementation
- Solved
- No attempts yet
Problem
INK is a platformer puzzle game where you steer a white square past various hazards to reach the goal. Each time the white square jumps, it scatters ink of a color. When the ink hits a transparent obstacle, the obstacle is dyed. After that, the player can see the dyed obstacle.
A stage is an grid. is the cell in row and column . Each cell is either empty or an obstacle. The player enters commands in total to steer the square. The commands are:
- Move commands: the uppercase letters
U,D,L,R, which move the square one cell up, down, left, or right. If the move takes the square outside the stage or onto an obstacle, the command is ignored. - Ink command: the lowercase letter
j. It increases the square's ink amount by 1. The ink amount is 0 at the start. - Jump command: the uppercase letter
J. The square jumps in place and scatters ink. The amount of scattered ink equals the square's current ink amount. Right after the jump, the square's ink amount becomes 0.
When ink of color and amount is scattered at , every obstacle cell with is painted . If an obstacle is already painted a different color, it is repainted with the color of the later ink that reaches it.
The ink color depends on the jump count and the ink string. The ink string is an uppercase string of length . The color of the -th jump is the -th character of the ink string, where is a non-negative integer and . For example, the 1st jump uses the 1st character, the 2nd jump uses the 2nd character, the -th jump uses the -th character, the -th jump uses the 1st character, and the -th jump uses the 2nd character.
Input
The first line has three integers , , and , separated by spaces. ()
The second line is the ink string.
The next lines give the stage. @ is the square, . is an empty cell, and # is an obstacle. There is exactly one square.
The last line contains the commands with no spaces between them.
Output
Print the final stage as lines of characters each.
Print @ for the square, . for an empty cell, # for an undyed obstacle, and the uppercase letter of the ink color for a dyed obstacle.