codeforces-scrape

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

1118C.md (2285B)


      1 Source: https://codeforces.com/problemset/problem/1118/C
      2 
      3 C. Palindromic Matrix
      4 
      5 time limit per test
      6 
      7 2 seconds
      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 Let's call some square matrix with integer values in its cells palindromic if it doesn't change after the order of rows is reversed and it doesn't change after the order of columns is reversed.
     22 
     23 For example, the following matrices are palindromic:
     24 
     25  ![](https://espresso.codeforces.com/8dc701bcc36ea857b76d61eb835a271e56da8b43.png) 
     26 
     27 The following matrices are not palindromic because they change after the order of rows is reversed:
     28 
     29  ![](https://espresso.codeforces.com/d8d1c0c64b4eca902989a98403e632f801f868d5.png) 
     30 
     31 The following matrices are not palindromic because they change after the order of columns is reversed:
     32 
     33  ![](https://espresso.codeforces.com/f92dafcc9e61696a6d7b39b890f15edfa0a3cc43.png) 
     34 
     35 You are given $n^2$ integers. Put them into a matrix of $n$ rows and $n$ columns so that each number is used exactly once, each cell contains exactly one number and the resulting matrix is palindromic. If there are multiple answers, print any. If there is no solution, print "NO".
     36 
     37 Input
     38 
     39 The first line contains one integer $n$ ($1 \le n \le 20$).
     40 
     41 The second line contains $n^2$ integers $a_1, a_2, \dots, a_{n^2}$ ($1 \le a_i \le 1000$) — the numbers to put into a matrix of $n$ rows and $n$ columns.
     42 
     43 Output
     44 
     45 If it is possible to put all of the $n^2$ numbers into a matrix of $n$ rows and $n$ columns so that each number is used exactly once, each cell contains exactly one number and the resulting matrix is palindromic, then print "YES". Then print $n$ lines with $n$ space-separated numbers — the resulting matrix.
     46 
     47 If it's impossible to construct any matrix, then print "NO".
     48 
     49 You can print each letter in any case (upper or lower). For example, "YeS", "no" and "yES" are all acceptable.
     50 
     51 Examples
     52 
     53 Input
     54 
     55 ```
     56 4
     57 1 8 8 1 2 2 2 2 2 2 2 2 1 8 8 1
     58 ```
     59 
     60 Output
     61 
     62 ```
     63 YES
     64 1 2 2 1
     65 8 2 2 8
     66 8 2 2 8
     67 1 2 2 1
     68 ```
     69 
     70 Input
     71 
     72 ```
     73 3
     74 1 1 1 1 1 3 3 3 3
     75 ```
     76 
     77 Output
     78 
     79 ```
     80 YES
     81 1 3 1
     82 3 1 3
     83 1 3 1
     84 ```
     85 
     86 Input
     87 
     88 ```
     89 4
     90 1 2 1 9 8 4 3 8 8 3 4 8 9 2 1 1
     91 ```
     92 
     93 Output
     94 
     95 ```
     96 NO
     97 ```
     98 
     99 Input
    100 
    101 ```
    102 1
    103 10
    104 ```
    105 
    106 Output
    107 
    108 ```
    109 YES
    110 10
    111 ```
    112 
    113 Note
    114 
    115 Note that there exist multiple answers for the first two examples.