307568: CF1375B. Neighbor Grid

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Neighbor Grid

题意翻译

### 题意: 给你一个 $n$ 行 $m$ 列的矩阵,要求你让这个矩阵是“完美”的。 “完美”的定义如下: 1. 若当前的格子里是一个正整数 $k$,那么与这个网格相邻(有公共边)的 $k$ 个格子也必须有一个正整数。 2. 若当前的格子里是 `0` ,那么不受上述的限制。 你可以对任意的一个格子加上 `1` ,次数不受限制。 对于每一组数据: 如果可以做到“完美”,请输出 `YES` 之后,将修改过的矩阵输出。 否则只输出一行 `NO` 。 ### 输入输出格式: **本题有多组测试数据**。 ### 输入格式: 第一行一个整数 $T$ ,表示测试数据的组数。 接下来对于每一组数据: 首先是一行两个整数 $n$ 和 $m$。 然后是一个 $n$ 行 $m$ 列的矩阵。 ### 输出格式: 对于每一组数据: 如果可以做到“完美”,请输出 `YES` 之后,将修改过的矩阵输出。 如果有多种可能,请输出任意一种。 若无法做到完美,只输出一行 `NO` 。 ### 数据范围: $1\le T\le 5000$。 $2\le n,m\le 300$。 $n \times m \le 10^5$ 对于每一个位置上的数字 $a_{(i,j)}$: $0 \le a_{(i,j)} \le 10^9$。 ------ + Translate by black_trees

题目描述

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 > 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.

输入输出格式

输入格式


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 $ .

输出格式


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.

输入输出样例

输入样例 #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

输出样例 #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

说明

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

题意翻译

### 题意: 给你一个 $n$ 行 $m$ 列的矩阵,要求你让这个矩阵是“完美”的。 “完美”的定义如下: 1. 若当前的格子里是一个正整数 $k$,那么与这个网格相邻(有公共边)的 $k$ 个格子也必须有一个正整数。 2. 若当前的格子里是 `0` ,那么不受上述的限制。 你可以对任意的一个格子加上 `1` ,次数不受限制。 对于每一组数据: 如果可以做到“完美”,请输出 `YES` 之后,将修改过的矩阵输出。 否则只输出一行 `NO` 。 ### 输入输出格式: **本题有多组测试数据**。 ### 输入格式: 第一行一个整数 $T$ ,表示测试数据的组数。 接下来对于每一组数据: 首先是一行两个整数 $n$ 和 $m$。 然后是一个 $n$ 行 $m$ 列的矩阵。 ### 输出格式: 对于每一组数据: 如果可以做到“完美”,请输出 `YES` 之后,将修改过的矩阵输出。 如果有多种可能,请输出任意一种。 若无法做到完美,只输出一行 `NO` 。 ### 数据范围: $1\le T\le 5000$。 $2\le n,m\le 300$。 $n \times m \le 10^5$ 对于每一个位置上的数字 $a_{(i,j)}$: $0 \le a_{(i,j)} \le 10^9$。 ------ + Translate by black_trees

加入题单

算法标签: