Apple
Time limit1sMemory limit128 MB
Simulate gravity, rotations, and waiting on a board with one apple, then print the final board state.
- Level
Medium7 of 10
- Topics
- Simulation, Implementation, Matrix
- Solved
- No attempts yet
Problem
A game board has rows and columns. Every cell is either empty or blocked, and one cell holds an apple. The apple always falls in the direction of gravity, which is toward the bottom of the screen.
Every second, the player may rotate the screen 90 degrees clockwise, rotate it 90 degrees counterclockwise, or wait and do nothing. The board turns together with the screen, and gravity keeps pointing toward the bottom of the screen. After that, the apple falls one cell toward the bottom of the screen, but only if the cell below it exists (is inside the board) and is empty. Otherwise the apple stays where it is.
Write a simulator for this game: given the initial board and a sequence of moves, print the final board. On the board, # marks a blocked cell, . marks an empty cell, and J marks the apple.
Input
The first line contains two positive integers and (), the number of rows and columns of the board.
Each of the next lines contains exactly characters. Each character is an uppercase J, a . (dot), or a #. The board contains exactly one J.
The last line contains the move sequence, a string of at most 1,000,000 characters. Each character is one of the following.
R: rotate the screen clockwise.L: rotate the screen counterclockwise.P: wait.
Output
Print the final board as it appears on the screen after all moves. Depending on the final rotation, it is a grid of rows and columns or a grid of rows and columns.