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

    ID: 8415 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 显示难度省选/NOI− 上传者: 标签>各省省选2021Special JudgeO2优化

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

Problem Description

Alice has an n×mn \times m matrix ai,ja_{i, j} (1≤i≤n1 \le i \le n, 1≤j≤m1 \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 (n−1)×(m−1)(n - 1) \times (m - 1) matrix bi,jb_{i, j} (1≤i≤n−11 \le i \le n - 1, 1≤j≤m−11 \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 n−1n - 1 lines each contain m−1m - 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: 1≤T≤101 \le T \le 10, 2≤n,m≤3002 \le n, m \le 300, 0≤bi,j≤4×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,m≤n, m \le Special Constraint
1∼41 \sim 4 33 None
5∼75 \sim 7 1010 m=2m = 2
8∼108 \sim 10 100100
11∼1511 \sim 15 300300 0≤bi,j≤10 \le b_{i, j} \le 1
16∼2016 \sim 20 None

Translated by ChatGPT 5