codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1797B.md (1951B)


      1 Source: https://codeforces.com/problemset/problem/1797/B
      2 
      3 B. Li Hua and Pattern
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 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}$?
     22 
     23 Suppose you were Li Hua, please solve this problem.
     24 
     25 Input
     26 
     27 The first line contains the single integer $t$ ($1 \le t \le 100$) — the number of test cases.
     28 
     29 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.
     30 
     31 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.
     32 
     33 It's guaranteed that sum of $n$ over all test cases does not exceed $10^3$.
     34 
     35 Output
     36 
     37 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.
     38 
     39 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.
     40 
     41 Example
     42 
     43 Input
     44 
     45 ```
     46 3
     47 
     48 4 0
     49 
     50 1 1 1 1
     51 
     52 0 0 0 1
     53 
     54 1 0 1 0
     55 
     56 1 1 1 1
     57 
     58 4 3
     59 
     60 1 0 1 1
     61 
     62 1 0 0 0
     63 
     64 0 1 0 1
     65 
     66 1 1 0 1
     67 
     68 5 4
     69 
     70 0 0 0 0 0
     71 
     72 0 1 1 1 1
     73 
     74 0 1 0 0 0
     75 
     76 1 1 1 1 1
     77 
     78 0 0 0 0 0
     79 ```
     80 
     81 Output
     82 
     83 ```
     84 NO
     85 YES
     86 YES
     87 ```
     88 
     89 Note
     90 
     91 In test case 1, you can't perform any operation. The pattern after rotation is on the right.
     92 
     93 |  |  |
     94 | --- | --- |
     95 |  |  |
     96 
     97 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.
     98 
     99 |  |  |  |
    100 | --- | --- | --- |
    101 |  |  |  |