No.3730 Jagged Minesweeper
Problem Statement
You are given $N$ strings $S_1, S_2, \ldots, S_N$, each of length $N$. Each $S_i$ consists only of 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, and $A_{i, j}$ denotes the integer represented by the $j$-th character of $S_i$.
There is an $N \times N$ grid, and the cell in the $i$-th row from the top and the $j$-th column from the left is denoted by $(i, j)$. Initially, nothing is placed on the grid.
You may place $0$ or $1$ bombs on each cell of the grid. You may also place no bombs at all.
Let $B_{i, j}$ be the number of bombs within the $3 \times 3$ area centered at cell $(i, j)$. Find one way to place bombs such that the following condition holds for all $1 \leq i, j \leq N$.
- If no bomb is placed on $(i, j)$, then $B_{i, j} \geq A_{i, j}$ holds; if a bomb is placed on it, then $B_{i, j} \leq A_{i, j}$ holds.
Here, the $3 \times 3$ area centered at cell $(i, j)$ refers to all cells $(x, y)$ that exist within the grid and satisfy $|x - i| \leq 1$ and $|y - j| \leq 1$. Note that it does not include anything outside the grid, and that cell $(i, j)$ itself is included in this area.
If no such placement of bombs exists, print -1.
Constraints
- $1 \leq N \leq 1000$
- $S_i$ is a string of length $N$ consisting only of
0,1,2,3,4,5,6,7,8,9
Input
The input is given from Standard Input in the following format.
$N$ $S_1$ $S_2$ $\vdots$ $S_N$
Output
If no valid placement exists, print -1. If one exists, print one such placement in the following format. Here, $T_i$ is a string of length $N$, and the $j$-th character of $T_i$ is o if a bomb is placed on the cell in the $i$-th row from the top and the $j$-th column from the left, and . if not.
$T_1$ $T_2$ $\vdots$ $T_N$
Print a newline at the end.
Visualizer
A web-based visualizer for the output is available here.
During the contest, sharing visualization results and discussing solutions or observations are prohibited. Please be careful.
In principle, questions about the specifications of the visualizer will not be accepted. Please use it only as an auxiliary tool.
Sample
Sample 1
Input
3 314 159 265
Output
o.o ..o ooo
The number of bombs within the $3 \times 3$ area centered at cell $(1, 1)$, which has a bomb, is $1$, so $B_{1, 1} = 1 \leq 3 = A_{1, 1}$ holds.
The number of bombs within the $3 \times 3$ area centered at cell $(1, 2)$, which has no bomb, is $3$, so $B_{1, 2} = 3 \geq 1 = A_{1, 2}$ holds.
The condition holds similarly for the other cells.
Sample 2
Input
2 00 00
Output
.. ..
It is fine to place no bombs at all.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。