CF1375B.Neighbor Grid

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a grid with nn rows and mm 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>0k \gt 0 written on it, then exactly kk of its neighboring cells have a number greater than 00 written on them. Note that if the number in the cell is 00, there is no such restriction on neighboring cells.

You are allowed to take any number in the grid and increase it by 11. 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.

给你一个 nn 行 mm 列的网格,每个格子中写有一个非负整数。我们称该网格是好的,当且仅当对每个格子均满足如下条件:若该格子中写的数为 k>0k \gt 0,则其恰好有 kk 个相邻格子中写的数大于 00。注意:若某格子中写的数为 00,则对其相邻格子没有任何限制。

你被允许对网格中的任意数字执行“将其增加 11”的操作。你可以对任意数字执行该操作任意多次(包括零次)。

请执行若干次(可能为零次)操作,使得网格变为“好的”;若不可能,请说明这一点。若存在多种可行方案,输出任意一种即可。

两个格子被认为是相邻的,当且仅当它们有一条公共边。

输入格式

The input consists of multiple test cases. The first line contains an integer tt (1≤t≤50001 \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 nn and mm (2≤n,m≤3002 \le n, m \le 300) — the number of rows and columns, respectively.

The following nn lines contain mm integers each, the jj-th element in the ii-th line ai,ja_{i, j} is the number written in the jj-th cell of the ii-th row (0≤ai,j≤1090 \le a_{i, j} \le 10^9).

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

输入包含多个测试用例。第一行包含一个整数 tt(1≤t≤50001 \le t \le 5000),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 mm(2≤n,m≤3002 \le n, m \le 300),分别表示行数和列数。

接下来的 nn 行,每行包含 mm 个整数;其中第 ii 行的第 jj 个元素 ai,ja_{i, j} 表示第 ii 行第 jj 列格子中所写的数字(0≤ai,j≤1090 \le a_{i, j} \le 10^9)。

保证所有测试用例中 n⋅mn \cdot m 的总和不超过 10510^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 nn lines each containing mm 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.

如果无法得到一个好网格,请输出一行包含 "NO" 的字符串。

否则,请先输出一行包含 "YES" 的字符串,然后输出 nn 行,每行包含 mm 个整数,描述网格的最终状态。该最终网格必须能通过(可能为零次)对初始网格执行若干操作而得到。

若存在多个可能的答案,你可以输出其中任意一个。

输入输出样例

  • 输入#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 22, column 33 once. Both of the cells that contain 11 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.

在第一个测试用例中,我们可以通过将第 22 行、第 33 列的数字增加 11 次来得到目标网格。所有包含 11 的格子均恰好有一个大于零的相邻格子,因此该网格是“好的”。许多其他解法也存在,例如以下网格:

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

所有这些解法均被视为有效答案。

在第二个测试用例中,无法使该网格变为“好的”。

在第三个测试用例中,请注意没有任何格子上的数字大于零,因此该网格自动为“好的”。

输入解题思路,AI测评打分。不知道怎么写?

首页