Problem Statement
You are given an $N\times N$ matrix $A=(A_{i,j})\ (1\leq i,j\leq N)$ and integer sequences of length $N$: $R=(R_1,R_2,\ldots,R_N), C=(C_1,C_2,\ldots,C_N)$. Each element of $A$ is $0$ or $1$, and each element of $R,C$ is at least $0$ and less than $\frac{N}{4}$.
You can freely choose a pair of strings $X,Y$ of length $N$ consisting of 0 and 1. Based on the chosen strings $X,Y$, perform the following operations:
- First, for each
$i=1,2,\ldots,N$, do the following. Let$X_i$be the$i$-th character of$X$: - If
$X_i$is0, do nothing.- If
$X_i$is1, flip all elements in the$i$-th row of$A$. That is, for each$j=1,2,\ldots,N$, replace$A_{i,j}$with$1-A_{i,j}$.
- If
- Next, for each
$j=1,2,\ldots,N$, do the following. Let$Y_j$be the$j$-th character of$Y$: - If
$Y_j$is0, do nothing.- If
$Y_j$is1, flip all elements in the$j$-th column of$A$. That is, for each$i=1,2,\ldots,N$, replace$A_{i,j}$with$1-A_{i,j}$.
- If
Determine whether it is possible to choose $X,Y$ cleverly so that the matrix $A$ after the operations satisfies the following conditions, and if possible, output one such pair.
- For each
$i=1,2,\ldots,N$, the sum of elements in the$i$-th row of$A$,$\displaystyle \sum_{j=1}^N A_{i,j}$, is$R_i$. - For each
$j=1,2,\ldots,N$, the sum of elements in the$j$-th column of$A$,$\displaystyle \sum_{i=1}^N A_{i,j}$, is$C_j$.
You are given $T$ test cases, so answer each of them.
Constraints
$1\leq T\leq 10^5$$1\leq N\leq 1000$$A_{i,j} \in\lbrace 0,1\rbrace$$0\leq R_i,C_j\lt \frac{N}{4}$$T,N,R_i,C_j$are integers.- The sum of
$N^2$over all test cases in one input file is at most$10^6$.
Input
The input is given from Standard Input in the following format:
T
\textrm{case}_1
\textrm{case}_2
\vdots
\textrm{case}_T
Each test case is given in the following format:
N
A_{1,1}A_{1,2}\dots A_{1,N}
A_{2,1}A_{2,2}\dots A_{2,N}
\vdots
A_{N,1}A_{N,2}\dots A_{N,N}
R_1 R_2 \ldots R_N
C_1 C_2 \ldots C_N
Output
Output your solutions for $\textrm{case}_1,\textrm{case}_2,\ldots,\textrm{case}_T$ in order in the following format:
If there is no pair $X,Y$ that satisfies the conditions, output No.
If there exists such a pair, output:
Yes
X
Y
If there are multiple solutions, any of them will be considered correct.
样例
3
2
10
01
0 0
0 0
5
10101
11110
01111
10011
00110
1 1 1 1 1
1 1 1 1 1
10
0001011010
0101101000
0000101111
0010011100
0111000001
0011100110
1110001110
1100110000
0110111011
1101101101
1 1 0 2 0 0 2 2 2 2
2 2 0 1 0 2 1 2 1 1
Yes
01
10
Yes
01101
10001
No
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。