P19285 [CodeChef] CONSADD
提高
题目描述

Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.

You are given two matrices $A$ and $B$, each with $R$ rows (numbered $1$ through $R$) and $C$ columns (numbered $1$ through $C$). Let's denote an element of $A$ or $B$ in row $i$ and column $j$ by $A_{i,j}$ or $B_{i,j}$ respectively.

You are also given an integer $X$. You may perform the following operation on $A$ any number of times:
Choose an integer $v$.
Choose $X$ consecutive elements of $A$, either in the same row or in the same column.
Add $v$ to each of the chosen elements of $A$.

Determine whether it is possible to change $A$ to $B$ in a finite number of operations.

------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains three space-separated integers $R$, $C$ and $X$.
$R$ lines follow. For each valid $i$, the $i$-th of these lines contains $C$ space-separated integers $A_{i,1}, A_{i,2}, \ldots, A_{i,C}$.
$R$ more lines follow. For each valid $i$, the $i$-th of these lines contains $C$ space-separated integers $B_{i,1}, B_{i,2}, \ldots, B_{i,C}$.

------ Output ------
For each test case, print a single line containing the string "Yes" if there is a sequence of operations that changes the matrix $A$ to $B$, or "No" if such a sequence of operations does not exist.

------ Constraints ------
$1 ≤ T ≤ 10^{3}$
$2 ≤ R,C ≤ 10^{3}$
$2 ≤ X ≤ \min(R,C)$
$|A_{i,j}|, |B_{i,j}| ≤ 10^{9}$ for each valid $i,j$
the sum of $R$ over all test cases does not exceed $10^{3}$
the sum of $C$ over all test cases does not exceed $10^{3}$

------ Subtasks ------
Subtask #1 (5 points): $X=2$

Subtask #2 (10 points): $X=3$

Subtask #3 (85 points): original constraints

----- Sample Input 1 ------
3

2 2 2

1 2

0 1

0 0

0 0

2 2 2

1 2

0 1

0 0

-1 0

3 2 2

1 1

2 2

3 3

1 0

2 0

3 0
----- Sample Output 1 ------
Yes

No

No
----- explanation 1 ------
Example case 1: We can add $-1$ to both elements in row $1$ and add $-1$ to both elements in column $2$.

Example case 2: After any operation, the sum of elements of $A$ remains even. However, the sum of elements of $B$ is odd, so $A$ cannot be changed to $B$.

输入格式

见题面

输出格式

见题面

样例输入
3 2 2 2 1 2 0 1 0 0 0 0 2 2 2 1 2 0 1 0 0 -1 0 3 2 2 1 1 2 2 3 3 1 0 2 0 3 0
样例输出
Yes No No