QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100 Hackable ✓

#6140. Matrix Game

Statistics

Alice has an $n \times m$ matrix $a_{i,j}$ ($1 \le i \le n$, $1 \le j \le m$), where each element is a non-negative integer not exceeding $10^6$. Bob generated an $(n-1) \times (m-1)$ matrix $b_{i,j}$ ($1 \le i \le n-1$, $1 \le j \le m-1$) from this matrix, where each element is generated by the formula:

$$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 $a_{i,j}$. Please reconstruct $a_{i,j}$ based on the matrix $b_{i,j}$ provided by Bob.

Input

The input contains multiple test cases. The first line contains an integer $T$ representing the number of test cases. For each test case, the first line contains two positive integers $n, m$, representing the size of the matrix $a_{i,j}$. The next $n-1$ lines each contain $m-1$ non-negative integers, representing $b_{i,j}$.

Output

For each test case: 1. If the matrix $b_{i,j}$ cannot be generated, output a single line containing the string NO. 2. If the matrix $b_{i,j}$ can be generated, first output a single line containing the string YES, followed by $n$ lines, each containing $m$ non-negative integers (separated by single spaces) not exceeding $10^6$, representing $a_{i,j}$. If there are multiple matrices $a_{i,j}$ that can generate the given $b_{i,j}$, you may output any one of them.

Constraints

For all test cases: $1 \le T \le 10$, $2 \le n, m \le 300$, $0 \le b_{i,j} \le 4 \times 10^6$. The specific constraints for each test case are as follows:

Test Case ID $n, m \le$ Special Constraints
$1 \sim 4$ $3$ None
$5 \sim 7$ $10$ $m = 2$
$8 \sim 10$ $100$ $m = 2$
$11 \sim 15$ $300$ $0 \le b_{i,j} \le 1$
$16 \sim 20$ $300$ None

Examples

Input 1

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

Output 1

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

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.