codeforces-scrape

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

1422B.md (1512B)


      1 Source: https://codeforces.com/problemset/problem/1422/B
      2 
      3 B. Nice Matrix
      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 A matrix of size $n \times m$ is called nice, if all rows and columns of the matrix are palindromes. A sequence of integers $(a_1, a_2, \dots , a_k)$ is a palindrome, if for any integer $i$ ($1 \le i \le k$) the equality $a_i = a_{k - i + 1}$ holds.
     22 
     23 Sasha owns a matrix $a$ of size $n \times m$. In one operation he can increase or decrease any number in the matrix by one. Sasha wants to make the matrix nice. He is interested what is the minimum number of operations he needs.
     24 
     25 Help him!
     26 
     27 Input
     28 
     29 The first line contains a single integer $t$ — the number of test cases ($1 \le t \le 10$). The $t$ tests follow.
     30 
     31 The first line of each test contains two integers $n$ and $m$ ($1 \le n, m \le 100$) — the size of the matrix.
     32 
     33 Each of the next $n$ lines contains $m$ integers $a_{i, j}$ ($0 \le a_{i, j} \le 10^9$) — the elements of the matrix.
     34 
     35 Output
     36 
     37 For each test output the smallest number of operations required to make the matrix nice.
     38 
     39 Example
     40 
     41 Input
     42 
     43 ```
     44 2
     45 4 2
     46 4 2
     47 2 4
     48 4 2
     49 2 4
     50 3 4
     51 1 2 3 4
     52 5 6 7 8
     53 9 10 11 18
     54 ```
     55 
     56 Output
     57 
     58 ```
     59 8
     60 42
     61 ```
     62 
     63 Note
     64 
     65 In the first test case we can, for example, obtain the following nice matrix in $8$ operations:
     66 
     67 ```
     68 2 2  
     69 4 4  
     70 4 4  
     71 2 2
     72 ```
     73 
     74 In the second test case we can, for example, obtain the following nice matrix in $42$ operations:
     75 
     76 ```
     77 5 6 6 5  
     78 6 6 6 6  
     79 5 6 6 5
     80 ```