lopta | 프로그래밍의 벗 PivotOJ
PivotOJ

lopta

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

문제

Game board consists of NxN small squares arranged in N rows and N columns. A square can be empty or occupied by a wall. There is a ball in one empty square on the board. Ball is under the influence of gravity, so it must always lie on a wall or on the floor of the game board. 

We can rotate the game board 90 degrees clockwise or counterclockwise. Walls and the ball are rotating together with the whole board. After the rotation, the ball drops down (influenced by gravity) on the first wall under it (or on the floor of the board). 

Example of a board first rotated clockwise and then counterclockwise: 

[이미지 1]

Write a program that will determine the layout of the board after a sequence of given rotations. 

입력

First line of input contains integers N and K, 1 ≤ N ≤ 1000, 1 ≤ K ≤ 500,000. 

Following N lines contain the initial description of the board: '.' (dot) denotes empty square, 'X' denotes wall, and 'L' the initial position of the ball. 

In each of the following K lines there is one character, either 'L' or 'D', representing the direction of rotation in the corresponding step. 'L' means counterclockwise and 'D' means clockwise rotation. 

출력

N lines of output should contain the layout of the board after all K given rotations. 

예제

예제 1

입력
6 2
....XX
X.....
......
..L...
.XXX..
......
L
D
출력
....XX
X.....
......
......
.XXX..
L.....

예제 2

입력
10 7
..........
XXXXXXXXX.
..X.....X.
..X.....X.
........X.
........X.
...X....X.
...X....X.
.XXXXXXXX.
L.........
L
L
L
L
D
D
L
출력
........X.
.X......X.
.X....XXX.
.XXX....X.
.X......X.
.X......X.
.X......X.
.X...L..X.
.XXXXXXXX.
..........

예제 3

입력
10 8
...XXX..XX
....XX...X
L....X..XX
X..X..X...
.......X..
..X.....X.
.X........
X...X.....
...X......
.....X....
D
L
D
L
D
D
D
L
출력
....X.....
......X...
.....X...X
........X.
.X.....X..
..X.......
...X..X..X
XX..X.....
X...XX....
XXL.XXX...
코드를 제출하려면 로그인하세요.