English · Original
Chinese · Translation
Formal · Original
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!
Vasya knows that the matrix consists of _n_ rows and _m_ columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence _a_1, _a_2, ..., _a__n_ denotes the xor of elements in rows with indices 1, 2, ..., _n_, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence _b_1, _b_2, ..., _b__m_ denotes the xor of elements in columns with indices 1, 2, ..., _m_, respectively.
Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
## Input
The first line contains two numbers _n_ and _m_ (2 ≤ _n_, _m_ ≤ 100) — the dimensions of the matrix.
The second line contains _n_ numbers _a_1, _a_2, ..., _a__n_ (0 ≤ _a__i_ ≤ 109), where _a__i_ is the xor of all elements in row _i_.
The third line contains _m_ numbers _b_1, _b_2, ..., _b__m_ (0 ≤ _b__i_ ≤ 109), where _b__i_ is the xor of all elements in column _i_.
## Output
If there is no matrix satisfying the given constraints in the first line, output "NO".
Otherwise, on the first line output "YES", and then _n_ rows of _m_ numbers in each _c__i_1, _c__i_2, ... , _c__im_ (0 ≤ _c__ij_ ≤ 2·109) — the description of the matrix.
If there are several suitable matrices, it is allowed to print any of them.
[samples]
现在 Vasya 正在参加一场数学考试。为了取得好成绩,Vasya 需要猜出老师构造的矩阵!
Vasya 知道该矩阵由 #cf_span[n] 行和 #cf_span[m] 列组成。对于每一行,他知道该行元素的异或(按位异或)。序列 #cf_span[a1, a2, ..., an] 表示索引为 #cf_span[1], #cf_span[2], ..., #cf_span[n] 的行中元素的异或。类似地,对于每一列,他知道该列元素的异或。序列 #cf_span[b1, b2, ..., bm] 表示索引为 #cf_span[1], #cf_span[2], ..., #cf_span[m] 的列中元素的异或。
帮助 Vasya!找出满足给定约束的矩阵,或告诉他不存在合适的矩阵。
第一行包含两个数 #cf_span[n] 和 #cf_span[m (2 ≤ n, m ≤ 100)] —— 矩阵的维度。
第二行包含 #cf_span[n] 个数 #cf_span[a1, a2, ..., an (0 ≤ ai ≤ 10^9)],其中 #cf_span[ai] 是第 #cf_span[i] 行所有元素的异或。
第三行包含 #cf_span[m] 个数 #cf_span[b1, b2, ..., bm (0 ≤ bi ≤ 10^9)],其中 #cf_span[bi] 是第 #cf_span[i] 列所有元素的异或。
如果不存在满足给定约束的矩阵,则在第一行输出 "NO"。
否则,在第一行输出 "YES",然后输出 #cf_span[n] 行,每行包含 #cf_span[m] 个数 #cf_span[ci1, ci2, ... , cim (0 ≤ cij ≤ 2·10^9)] —— 矩阵的描述。
如果存在多个符合条件的矩阵,允许输出其中任意一个。
## Input
第一行包含两个数 #cf_span[n] 和 #cf_span[m (2 ≤ n, m ≤ 100)] —— 矩阵的维度。第二行包含 #cf_span[n] 个数 #cf_span[a1, a2, ..., an (0 ≤ ai ≤ 10^9)],其中 #cf_span[ai] 是第 #cf_span[i] 行所有元素的异或。第三行包含 #cf_span[m] 个数 #cf_span[b1, b2, ..., bm (0 ≤ bi ≤ 10^9)],其中 #cf_span[bi] 是第 #cf_span[i] 列所有元素的异或。
## Output
如果不存在满足给定约束的矩阵,则在第一行输出 "NO"。否则,在第一行输出 "YES",然后输出 #cf_span[n] 行,每行包含 #cf_span[m] 个数 #cf_span[ci1, ci2, ... , cim (0 ≤ cij ≤ 2·10^9)] —— 矩阵的描述。如果存在多个符合条件的矩阵,允许输出其中任意一个。
[samples]
**Definitions**
Let $ n, m \in \mathbb{Z} $ be the dimensions of the matrix, with $ 2 \leq n, m \leq 100 $.
Let $ A = (a_1, a_2, \dots, a_n) \in \mathbb{Z}_{\geq 0}^n $ be the row XOR constraints.
Let $ B = (b_1, b_2, \dots, b_m) \in \mathbb{Z}_{\geq 0}^m $ be the column XOR constraints.
Let $ C = (c_{ij}) \in \mathbb{Z}_{\geq 0}^{n \times m} $ be the matrix to be constructed, with $ 0 \leq c_{ij} \leq 2 \cdot 10^9 $.
**Constraints**
1. For each row $ i \in \{1, \dots, n\} $:
$$
\bigoplus_{j=1}^{m} c_{ij} = a_i
$$
2. For each column $ j \in \{1, \dots, m\} $:
$$
\bigoplus_{i=1}^{n} c_{ij} = b_j
$$
3. The total XOR of all elements computed via rows must equal that via columns:
$$
\bigoplus_{i=1}^{n} a_i = \bigoplus_{j=1}^{m} b_j
$$
**Objective**
Determine whether there exists a matrix $ C $ satisfying the above constraints. If yes, output any such matrix; otherwise, output "NO".
API Response (JSON)
{
"problem": {
"name": "D. Vasya And The Matrix",
"description": {
"content": "Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed! Vasya knows that the matrix consists of _n_ rows and _m_ col",
"description_type": "Markdown"
},
"platform": "Codeforces",
"limit": {
"time_limit": 2000,
"memory_limit": 262144
},
"difficulty": "None",
"is_remote": true,
"is_sync": true,
"sync_url": null,
"sign": "CF1016D"
},
"statements": [
{
"statement_type": "Markdown",
"content": "Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!\n\nVasya knows that the matrix consists of _n_ rows and _m_ col...",
"is_translate": false,
"language": "English"
},
{
"statement_type": "Markdown",
"content": "现在 Vasya 正在参加一场数学考试。为了取得好成绩,Vasya 需要猜出老师构造的矩阵!\n\nVasya 知道该矩阵由 #cf_span[n] 行和 #cf_span[m] 列组成。对于每一行,他知道该行元素的异或(按位异或)。序列 #cf_span[a1, a2, ..., an] 表示索引为 #cf_span[1], #cf_span[2], ..., #cf_span[n] 的行中元素的异...",
"is_translate": true,
"language": "Chinese"
},
{
"statement_type": "Markdown",
"content": "**Definitions** \nLet $ n, m \\in \\mathbb{Z} $ be the dimensions of the matrix, with $ 2 \\leq n, m \\leq 100 $. \nLet $ A = (a_1, a_2, \\dots, a_n) \\in \\mathbb{Z}_{\\geq 0}^n $ be the row XOR constraints....",
"is_translate": false,
"language": "Formal"
}
]
}