CF1422B.Nice Matrix

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

A matrix of size n×mn \times m is called nice, if all rows and columns of the matrix are palindromes. A sequence of integers (a1,a2,,ak)(a_1, a_2, \dots , a_k) is a palindrome, if for any integer ii ( 1ik1 \le i \le k ) the equality ai=aki+1a_i = a_{k - i + 1} holds.

Sasha owns a matrix aa of size n×mn \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.

Help him!

输入格式

The first line contains a single integer tt — the number of test cases ( 1t101 \le t \le 10 ). The tt tests follow.

The first line of each test contains two integers nn and mm ( 1n,m1001 \le n, m \le 100 ) — the size of the matrix.

Each of the next nn lines contains mm integers ai,ja_{i, j} ( 0ai,j1090 \le a_{i, j} \le 10^9 ) — the elements of the matrix.

输出格式

For each test output the smallest number of operations required to make the matrix nice.

输入输出样例

  • 输入#1

    2
    4 2
    4 2
    2 4
    4 2
    2 4
    3 4
    1 2 3 4
    5 6 7 8
    9 10 11 18

    输出#1

    8
    42

说明/提示

In the first test case we can, for example, obtain the following nice matrix in 88 operations:

<pre class="verbatim"><br></br>2 2<br></br>4 4<br></br>4 4<br></br>2 2<br></br>

In the second test case we can, for example, obtain the following nice matrix in 4242 operations:

<pre class="verbatim"><br></br>5 6 6 5<br></br>6 6 6 6<br></br>5 6 6 5<br></br>
首页