A13834 | Nice Matrix
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
Help him!
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.
Help him!
输入格式
The first line contains a single integer $t$ — the number of test cases ( $1 \le t \le 10$ ). The $t$ tests follow.
The first line of each test contains two integers $n$ and $m$ ( $1 \le n, m \le 100$ ) — the size of the matrix.
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.
The first line of each test contains two integers $n$ and $m$ ( $1 \le n, m \le 100$ ) — the size of the matrix.
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.
输出格式
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 $8$ 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 $42$ operations:
```
<pre class="verbatim"><br></br>5 6 6 5<br></br>6 6 6 6<br></br>5 6 6 5<br></br>
```
```
<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 $42$ operations:
```
<pre class="verbatim"><br></br>5 6 6 5<br></br>6 6 6 6<br></br>5 6 6 5<br></br>
```
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted