No.351 Checkered Slide Puzzle
タグ : / 解いたユーザー数 204
作問者 :
nmnmnmnmnmnmnm
Problem Statement
There is an $H \times W$ grid of cells with height $H$ and width $W$.
The rows are numbered from $0$ to $H-1$ vertically, and the columns are numbered from $0$ to $W-1$ horizontally.
Each cell is painted white or black, and all the cells form a checkered pattern.
The top-left cell is white.
A can perform either of the following operations on the grid.
・Choose row $x$ (0-indexed) and slide it by 1 cell from the left. (The rightmost cell that is pushed out moves to the leftmost position.)
・Choose column $y$ (0-indexed) and slide it by 1 cell from the top. (The bottommost cell that is pushed out moves to the topmost position.)
For example, suppose that the initial state has $H=4$ and $W=5$, and consider the following case.
・Choose row 1 and slide it by 1 cell from the left. (The rightmost cell that is pushed out moves to the leftmost position.)
・Choose column 4 and slide it by 1 cell from the top. (The rightmost cell that is pushed out moves to the leftmost position.)
・Choose row 0 and slide it by 1 cell from the left. (The rightmost cell that is pushed out moves to the leftmost position.)
The figure below illustrates the case where the above 3 operations are performed.
In this case, the top-left cell finally becomes black.
The operations A performed are given as input.
Determine the final color of the top-left cell.
Note
This may be difficult in LL-family languages. Please be careful.Input
$H$ $W$
$N$
$S_0$ $K_0$
$S_1$ $K_1$
$ \vdots\ $
$S_{N-1}$ $K_{N-1}$
$H$ and $W$ represent the number of cells vertically and horizontally, respectively. $1\le H,W \le 10000$.
$N$ represents the number of operations A performed. $1\le N \le 1000000$.
$S_i$ represents the type of the $i$-th operation A performed.
It is either 'R' for a row operation or 'C' for a column operation.
$K_i$ is the number of the row or column of the $i$-th operation A performed.
When $S_i$='R', $0\le K_i \le H-1$; when $S_i$='C', $0\le K_i \le W-1$.
Output
Output the color of the top-left cell after A has performed all the operations, on one line.
Output "white" if it is white, and "black" if it is black.
Do not forget the newline at the end.
Sample
Sample 1
Input
4 5 3 R 1 C 4 R 0
Output
black
This is the same as the example in the problem statement.
Sample 2
Input
5 5 4 C 3 R 2 C 3 R 4
Output
white
The top-left cell never moves.
Sample 3
Input
6 5 10 C 0 C 2 R 5 C 3 R 0 C 2 R 3 C 1 C 2 R 0
Output
white
Sample 4
Input
1 2 5 C 0 R 0 C 0 R 0 C 1
Output
white
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。