A16189 | Perfect Square
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Kristina has a matrix of size $n$ by $n$ , filled with lowercase Latin letters. The value of $n$ is even.
She wants to change some characters so that her matrix becomes a perfect square. A matrix is called a perfect square if it remains unchanged when rotated $90^\circ$ clockwise once.
Here is an example of rotating a matrix by $90^\circ$ :
In one operation, Kristina can choose any cell and replace its value with the next character in the alphabet. If the character is equal to "z", its value does not change.
Find the minimum number of operations required to make the matrix a perfect square.
For example, if the $4$ by $4$ matrix looks like this:
$$$$\matrix{ a & b & b & a \cr b & c & \textbf{b} & b \cr b & c & c & b\cr a & b & b & a \cr } $$ </p><p>then it is enough to apply $1$$$ operation to the letter b, highlighted in bold.
She wants to change some characters so that her matrix becomes a perfect square. A matrix is called a perfect square if it remains unchanged when rotated $90^\circ$ clockwise once.
Here is an example of rotating a matrix by $90^\circ$ :
In one operation, Kristina can choose any cell and replace its value with the next character in the alphabet. If the character is equal to "z", its value does not change.
Find the minimum number of operations required to make the matrix a perfect square.
For example, if the $4$ by $4$ matrix looks like this:
$$$$\matrix{ a & b & b & a \cr b & c & \textbf{b} & b \cr b & c & c & b\cr a & b & b & a \cr } $$ </p><p>then it is enough to apply $1$$$ operation to the letter b, highlighted in bold.
输入格式
The first line of the input contains a single integer $t$ ( $1 \le t \le 10^2$ ) — the number of test cases.
Then follows the description of each test case.
The first line of each test case contains a single even integer $n$ ( $2 \le n \le 10^3$ ) — the number of rows and columns in the matrix.
Then follows $n$ lines, each containing exactly $n$ lowercase Latin letters.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^3$ .
Then follows the description of each test case.
The first line of each test case contains a single even integer $n$ ( $2 \le n \le 10^3$ ) — the number of rows and columns in the matrix.
Then follows $n$ lines, each containing exactly $n$ lowercase Latin letters.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^3$ .
输出格式
For each test case, output a single number on a separate line: the minimum number of operations required for Kristina to obtain a perfect square.
输入输出样例
输入 #1
5 4 abba bcbb bccb abba 2 ab ba 6 codefo rcesco deforc escode forces codefo 4 baaa abba baba baab 4 bbaa abba aaba abba
输出 #1
1 2 181 5 9
The first test case is explained in the problem statement.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted