Codeforces Round 864 (Div. 2)
B
Li Hua and Pattern
Codeforces
1100
原题
← AC →
翻译中…

Li Hua has a pattern of size $n\times n$, each cell is either blue or red. He can perform exactly $k$ operations. In each operation, he chooses a cell and changes its color from red to blue or from blue to red. Each cell can be chosen as many times as he wants. Is it possible to make the pattern, that matches its rotation by $180^{\circ}$?

翻译中…

Suppose you were Li Hua, please solve this problem.

翻译中…

Input

翻译中…

The first line contains the single integer $t$ ($1 \le t \le 100$) — the number of test cases.

翻译中…

The first line of each test case contains two integers $n,k$ ($1\le n\le 10^3,0\le k \le 10^9$) — the size of the pattern and the number of operations.

翻译中…

Each of next $n$ lines contains $n$ integers $a_{i,j}$ ($a_{i,j}\in\{0,1\}$) — the initial color of the cell, $0$ for blue and $1$ for red.

翻译中…

It's guaranteed that sum of $n$ over all test cases does not exceed $10^3$.

翻译中…

Output

翻译中…

For each set of input, print "YES" if it's possible to make the pattern, that matches its rotation by $180^{\circ}$ after applying exactly $k$ of operations, and "NO" otherwise.

翻译中…

You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.

翻译中…

Note

翻译中…

In test case 1, you can't perform any operation. The pattern after rotation is on the right.

翻译中…

imageimage

翻译中…

In test case 2, you can perform operations on $(2,1),(3,2),(3,4)$. The pattern after operations is in the middle and the pattern after rotation is on the right.

翻译中…

imageimageimage

翻译中…

样例

Input #1
3
4 0
1 1 1 1
0 0 0 1
1 0 1 0
1 1 1 1
4 3
1 0 1 1
1 0 0 0
0 1 0 1
1 1 0 1
5 4
0 0 0 0 0
0 1 1 1 1
0 1 0 0 0
1 1 1 1 1
0 0 0 0 0
Output #1
NO
YES
YES
InputCopy OutputCopy
题目信息
题号
1797B
时间限制
1 s
内存限制
256 MB
标签
构造
贪心

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。