#P7515. [省选联考 2021 A 卷] 矩阵游戏

[省选联考 2021 A 卷] 矩阵游戏

Description

Alice has an n×mn \times m matrix ai,ja_{i, j} (1in1 \le i \le n, 1jm1 \le j \le m), where each element is a non-negative integer with value at most 106{10}^6.

Bob uses this matrix to generate an (n1)×(m1)(n - 1) \times (m - 1) matrix bi,jb_{i, j} (1in11 \le i \le n - 1, 1jm11 \le j \le m - 1). Each element is generated by

$$b_{i, j} = a_{i, j} + a_{i, j + 1} + a_{i + 1, j} + a_{i + 1, j + 1}$$

Now Alice has forgotten the matrix ai,ja_{i, j}. Please restore ai,ja_{i, j} from the matrix bi,jb_{i, j} given by Bob.

Input Format

This problem has multiple test cases.

The first line contains an integer TT, the number of test cases. For each test case:

The first line contains two positive integers n,mn, m, the size of matrix ai,ja_{i, j}.
The next n1n - 1 lines each contain m1m - 1 non-negative integers, representing bi,jb_{i, j}.

Output Format

For each test case:

  1. If the matrix bi,jb_{i, j} cannot be generated, output one line containing the string NO.
  2. If the matrix bi,jb_{i, j} can be generated, first output one line containing the string YES, then output nn lines each containing mm non-negative integers (separated by single spaces) with value at most 106{10}^6, representing ai,ja_{i, j}.

If multiple matrices ai,ja_{i, j} can generate the given bi,jb_{i, j}, output any one of them.

3
3 3
28 25
24 25
3 3
15 14
14 12
3 3
0 3000005
0 0

YES
7 8 8
8 5 4
4 7 9
YES
4 2 2
5 4 6
5 0 2
NO

Hint

Constraints

For all testdata: 1T101 \le T \le 10, 2n,m3002 \le n, m \le 300, 0bi,j4×1060 \le b_{i, j} \le 4 \times {10}^6.

The detailed limits for each test point are shown in the table below:

Test Point ID n,mn, m \le Special Constraint
141 \sim 4 33 None
575 \sim 7 1010 m=2m = 2
8108 \sim 10 100100
111511 \sim 15 300300 0bi,j10 \le b_{i, j} \le 1
162016 \sim 20 None

Translated by ChatGPT 5