P16481 [CodeChef] XORFOLD
提高-
题目描述

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

You are given a grid with size $N \times M$. Each cell of this grid contains either $0$ or $1$.

We should perform the following operation until the size of the grid becomes $1 \times 1$:
Suppose the present size of the grid is $x \times y$.
Choose one of the $x-1$ horizontal lines or $y-1$ vertical lines crossing the grid.
Fold the grid along this line. For each pair of cells which overlap after this folding, replace them by a single cell such that the value in this cell is the XOR of the values in the two overlapping cells. Thus, we obtain a new grid.

Example: If the initial grid is

000
111
010

1) After folding along $1$-st horizontal line, the grid is

111
010

2) After folding along the $2$-nd vertical line, the grid is

10
01

3) After folding along the $1$-st horizontal line, the grid is

11

4) After folding along the $1$-st vertical line, the grid is

0

Determine whether there is a sequence of folds such that in the final $1 \times 1$ grid, the only cell contains $1$.

------ 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 two space-separated integers $N$ and $M$.
$N$ lines follow. For each valid $i$, the $i$-th of these lines contains a single binary string $S_{i}$ with length $M$ describing the $i$-th row of the grid.

------ Output ------
Print a single line containing the string "YES" if it is possible to obtain $1$ in the final $1 \times 1$ grid or "NO" if it is impossible (without quotes).

You may print each character of the string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).

------ Constraints ------
$1 ≤ T ≤ 2 \cdot 10^{4}$
$1 ≤ N \cdot M ≤ 10^{5}$
each character of each string is '0' or '1'
the sum of $N \cdot M$ over all test cases does not exceed $10^{6}$

----- Sample Input 1 ------
2
1 2
01
3 3
000
111
010
----- Sample Output 1 ------
YES
NO
----- explanation 1 ------
Example case 1: There is only $1$ possible move, which is to fold along the only vertical line. The resulting grid contains only $1$.

Example case 2: There is no sequence of moves which would result in a $1 \times 1$ grid containing only $1$.

输入格式

见题面

输出格式

见题面

样例输入
2 1 2 01 3 3 000 111 010
样例输出
YES NO