#P16443. [XJTUPC 2026] 矩阵拆分
[XJTUPC 2026] 矩阵拆分
Problem Description
You are given an non-negative integer matrix . You need to construct an non-negative integer matrix such that:
- . Here, denotes the transpose of , which is the matrix obtained by swapping its rows and columns (the element in row and column of is located in row and column of ).
- For any , we have
- For any , we have
Or report that there is no solution.
Here, is the element in row and column of matrix , and is the element in row and column of matrix .
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 (), which is the number of test cases.
Next are the descriptions of the test cases.
The first line of each test case contains an integer (), which is the size of the matrix.
The next lines each contain integers separated by spaces, describing matrix . The -th integer in the -th line is ().
It is guaranteed that the sum of over all test cases does not exceed .
Output Format
For each test case, if there is no solution, output one line containing only the string .
Otherwise, output lines, where:
- The first line contains the string .
- The next lines each contain integers separated by spaces, describing the matrix . The -th integer in the -th line is ().
If there are multiple solutions, you may output any one.
The answer is case-insensitive. For example, , , , and will all be considered as .
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