#P16443. [XJTUPC 2026] 矩阵拆分

    ID: 18474 远端评测题 1500ms 512MiB 尝试: 0 已通过: 0 显示难度省选/NOI− 上传者: 标签>Special Judge2026高校校赛

[XJTUPC 2026] 矩阵拆分

Problem Description

You are given an n×nn \times n non-negative integer matrix BB. You need to construct an n×nn \times n non-negative integer matrix AA such that:

  • A+AT=BA + A^\mathsf{T} = B. Here, ATA^\mathsf{T} denotes the transpose of AA, which is the matrix obtained by swapping its rows and columns (the element in row ii and column jj of AA is located in row jj and column ii of ATA^\mathsf{T}).
  • For any i=1,2,⋯ ,ni = 1,2,\cdots , n, we have
$$\left\lfloor \frac{1}{2}\sum\limits_{j=1}^n B_{ij} \right\rfloor \le \sum\limits_{j=1}^n A_{ij} \le \left\lceil \frac{1}{2}\sum\limits_{j=1}^n B_{ij} \right\rceil$$
  • For any j=1,2,⋯ ,nj = 1,2,\cdots , n, we have
$$\left\lfloor \frac{1}{2}\sum\limits_{i=1}^n B_{ij}\right\rfloor \le \sum\limits_{i=1}^n A_{ij} \le \left\lceil \frac{1}{2}\sum\limits_{i=1}^n B_{ij} \right\rceil$$

Or report that there is no solution.

Here, AijA_{ij} is the element in row ii and column jj of matrix AA, and BijB_{ij} is the element in row ii and column jj of matrix BB.

If there are multiple solutions, you may output any one.

Input Format

This problem contains multiple test cases. The first line contains a positive integer TT (1≤T≤10001 \leq T \leq 1000), which is the number of test cases.

Next are the descriptions of the TT test cases.

The first line of each test case contains an integer nn (1≤n≤22001 \le n \le 2200), which is the size of the matrix.

The next nn lines each contain nn integers separated by spaces, describing matrix BB. The jj-th integer in the ii-th line is BijB_{ij} (0≤Bij≤1090 \leq B_{ij} \leq 10^9).

It is guaranteed that the sum of n2n^2 over all test cases does not exceed 5×1065 \times 10^6.

Output Format

For each test case, if there is no solution, output one line containing only the string No\tt{No}.

Otherwise, output n+1n + 1 lines, where:

  • The first line contains the string Yes\tt{Yes}.
  • The next nn lines each contain nn integers separated by spaces, describing the matrix AA. The jj-th integer in the ii-th line is AijA_{ij} (0≤Aij≤1090 \leq A_{ij} \leq 10^9).

If there are multiple solutions, you may output any one.

The answer is case-insensitive. For example, yEs\tt{yEs}, Yes\tt{Yes}, yes\tt{yes}, and YES\tt{YES} will all be considered as Yes\tt{Yes}.

3
4
2 1 0 0
1 2 0 0
0 0 2 3
0 0 3 2
4
0 2 1 2
2 0 3 3
1 3 0 2
2 3 2 0
3
1 2 3
4 5 6
7 8 9
Yes
1 1 0 0
0 1 0 0
0 0 1 2
0 0 1 1
Yes
0 1 1 1
1 0 1 2
0 2 0 1
1 1 1 0
No

Hint

Translated by ChatGPT 5