codeforces-scrape

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

1634C.md (2569B)


      1 Source: https://codeforces.com/problemset/problem/1634/C
      2 
      3 C. OKEA
      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 People worry that computers will get too smart and take over the world, but the real problem is that they're too stupid and they've already taken over the world.
     22 
     23 — Pedro Domingos
     24 
     25 You work for a well-known department store that uses leading technologies and employs mechanistic work — that is, robots!
     26 
     27 The department you work in sells $n \cdot k$ items. The first item costs $1$ dollar, the second item costs $2$ dollars, and so on: $i$-th item costs $i$ dollars. The items are situated on shelves. The items form a rectangular grid: there are $n$ shelves in total, and each shelf contains exactly $k$ items. We will denote by $a_{i,j}$ the price of $j$-th item (counting from the left) on the $i$-th shelf, $1 \le i \le n, 1 \le j \le k$.
     28 
     29 Occasionally robots get curious and ponder on the following question: what is the mean price (arithmetic average) of items $a_{i,l}, a_{i,l+1}, \ldots, a_{i,r}$ for some shelf $i$ and indices $l \le r$? Unfortunately, the old robots can only work with whole numbers. If the mean price turns out not to be an integer, they break down.
     30 
     31 You care about robots' welfare. You want to arrange the items in such a way that the robots cannot theoretically break. Formally, you want to choose such a two-dimensional array $a$ that:
     32 
     33 * Every number from $1$ to $n \cdot k$ (inclusively) occurs exactly once.
     34 * For each $i, l, r$, the mean price of items from $l$ to $r$ on $i$-th shelf is an integer.
     35 
     36 Find out if such an arrangement is possible, and if it is, give any example of such arrangement.
     37 
     38 Input
     39 
     40 The first line contains a single integer $t$ ($1 \le t \le 500$) — the number of test cases.
     41 
     42 The first and only line of each test case contains two integers $n$ and $k$ ($1 \le n, k \le 500$) — the number of shelves and length of each shelf, respectively.
     43 
     44 It is guaranteed that the sum $n$ over all test cases does not exceed $500$ and the sum $k$ over all test cases does not exceed $500$.
     45 
     46 Output
     47 
     48 Print the answer for each test case.
     49 
     50 If such an arrangement exists, print "YES" on a single line. After that, print any example on $n$ lines of $k$ numbers each, one line per shelf. Each number from $1$ to $n \cdot k$ must occur exactly once in the output.
     51 
     52 If no good arrangement exists, print a single word "NO" on its own line.
     53 
     54 Example
     55 
     56 Input
     57 
     58 ```
     59 4
     60 
     61 1 1
     62 
     63 2 2
     64 
     65 3 3
     66 
     67 3 1
     68 ```
     69 
     70 Output
     71 
     72 ```
     73 YES
     74 1 
     75 YES
     76 1 3 
     77 2 4 
     78 NO
     79 YES
     80 1 
     81 2 
     82 3
     83 ```