Rotate
Time limit2sMemory limit512 MB
Given an N by N letter board and Q square regions, print the board after rotating each region 90 degrees counterclockwise in order.
- Level
Medium5 of 10
- Topics
- Matrix, Simulation, Array
- Solved
- No attempts yet
Problem
There is a board of cells arranged in rows and columns. The cell in the -th row from the top and the -th column from the left is called cell . Cell contains the letter .
Rotate a square region 90 degrees counterclockwise, repeating this operation times. The -th rotation takes the square region whose top-left cell is and rotates it.
Find the final board.
Input
The first line contains integers and , separated by a space. is the board size and is the number of rotations.
The next lines give the initial board. The -th character of the -th line is . Each string contains only lowercase English letters.
The next lines give the rotations. The -th line contains integers , , and , separated by spaces. This means the -th rotation takes the square region whose top-left cell is and rotates it. Here , , and .
Output
Print the final board in lines. The -th line is a string of characters, whose -th character is the letter in cell of the final board.
Constraints
- (board size)
- (number of rotations)