Codeforces Global Round 9
B
Neighbor Grid
Codeforces
1200
原题
← AC →
翻译中…

You are given a grid with $n$ rows and $m$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $k \gt 0$ written on it, then exactly $k$ of its neighboring cells have a number greater than $0$ written on them. Note that if the number in the cell is $0$, there is no such restriction on neighboring cells.

翻译中…

You are allowed to take any number in the grid and increase it by $1$. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.

翻译中…

Two cells are considered to be neighboring if they have a common edge.

翻译中…

Input

翻译中…

The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 5000$)  — the number of test cases. The description of the test cases follows.

翻译中…

The first line of each test case contains two integers $n$ and $m$ ($2 \le n, m \le 300$)  — the number of rows and columns, respectively.

翻译中…

The following $n$ lines contain $m$ integers each, the $j$-th element in the $i$-th line $a_{i, j}$ is the number written in the $j$-th cell of the $i$-th row ($0 \le a_{i, j} \le 10^9$).

翻译中…

It is guaranteed that the sum of $n \cdot m$ over all test cases does not exceed $10^5$.

翻译中…

Output

翻译中…

If it is impossible to obtain a good grid, print a single line containing "NO".

翻译中…

Otherwise, print a single line containing "YES", followed by $n$ lines each containing $m$ integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero).

翻译中…

If there are multiple possible answers, you may print any of them.

翻译中…

Note

翻译中…

In the first test case, we can obtain the resulting grid by increasing the number in row $2$, column $3$ once. Both of the cells that contain $1$ have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid

翻译中…

$$0\;1\;0\;0$$ $$0\;2\;1\;0$$ $$0\;0\;0\;0$$

翻译中…

All of them are accepted as valid answers.

翻译中…

In the second test case, it is impossible to make the grid good.

翻译中…

In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good.

翻译中…

样例

Input #1
5
3 4
0 0 0 0
0 1 0 0
0 0 0 0
2 2
3 0
0 0
2 2
0 0
0 0
2 3
0 0 0
0 4 0
4 4
0 0 0 0
0 2 0 1
0 0 0 0
0 0 0 0
Output #1
YES
0 0 0 0
0 1 1 0
0 0 0 0
NO
YES
0 0
0 0
NO
YES
0 1 0 0
1 4 2 1
0 2 0 0
1 3 1 0
InputCopy OutputCopy
题目信息
题号
1375B
时间限制
1 s
内存限制
256 MB
标签
构造
贪心

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。