No.2432 Flip and Move
Problem Statement
There is an $H \times W$ grid, and each cell is painted either white or black. The cell in the $i$-th row from the top and the $j$-th column from the left is denoted by $(i,j)$.
By operating a recoloring robot placed on this grid some number of times, the colors of the cells change.
The state of the robot consists of its current cell, its vertical direction (up or down), and its horizontal direction (left or right).
The robot cannot move outside the grid.
In $1$ operation, the robot performs the following actions in order.
- Flip the color of the current cell. (White becomes black, and black becomes white.)
- If it can move $1$ cell in its current vertical direction, it moves $1$ cell. If it cannot, it reverses its vertical direction and stays in that cell.
- If it can move $1$ cell in its current horizontal direction, it moves $1$ cell. If it cannot, it reverses its horizontal direction and stays in that cell.
Initially, all cells are painted white, the robot is placed on cell $(1, 1)$, its vertical direction is down, and its horizontal direction is right.
When the robot is operated $K$ times, find the final color of each cell.
Input
$H\ W$ $K$
- $1 \le H$
- $1 \le W$
- $H \times W \le 10^6$
- $1 \le K \le 10^{18}$
- All inputs are integers.
Output
Let $S_{i, j}$ denote the color of cell $(i, j)$, where $S_{i, j} =$. if it is white and $S_{i, j} =$ # if it is black.Output in the following format.
$S_{1,1} S_{1,2}\ldots S_{1,W}$
$S_{2,1} S_{2,2}\ldots S_{2,W}$
$\vdots$
$S_{H,1} S_{H,2}\ldots S_{H,W}$
Sample
Sample 1
Input
2 3 4
Output
#.# .##
The robot flips the colors of cells $(1, 1)$, $(2, 2)$, $(2, 3)$, $(1, 3)$ in this order.
Sample 2
Input
2 2 3
Output
#. ..
The robot flips the colors of cells $(1, 1)$, $(2, 2)$, $(2, 2)$ in this order.
Sample 3
Input
11 7 1024
Output
###..## ##.##.# #.####. .#####. .####.# #.##.## ##..### ##..### #.##.## .####.# ..####.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
noya2