Codeforces Round 745 (Div. 1)
A
Portal
Codeforces
1700
原题
←B →
翻译中…

CQXYM found a rectangle $A$ of size $n \times m$. There are $n$ rows and $m$ columns of blocks. Each block of the rectangle is an obsidian block or empty. CQXYM can change an obsidian block to an empty block or an empty block to an obsidian block in one operation.

翻译中…

A rectangle $M$ size of $a \times b$ is called a portal if and only if it satisfies the following conditions:

翻译中…
  • $a \geq 5,b \geq 4$.
  • For all $1 \lt x \lt a$, blocks $M_{x,1}$ and $M_{x,b}$ are obsidian blocks.
  • For all $1 \lt x \lt b$, blocks $M_{1,x}$ and $M_{a,x}$ are obsidian blocks.
  • For all $1 \lt x \lt a,1 \lt y \lt b$, block $M_{x,y}$ is an empty block.
  • $M_{1, 1}, M_{1, b}, M_{a, 1}, M_{a, b}$ can be any type.
翻译中…

Note that the there must be $a$ rows and $b$ columns, not $b$ rows and $a$ columns.

翻译中…

Note that corners can be any type

翻译中…

CQXYM wants to know the minimum number of operations he needs to make at least one sub-rectangle a portal.

翻译中…

Input

翻译中…

The first line contains an integer $t$ ($t \geq 1$), which is the number of test cases.

翻译中…

For each test case, the first line contains two integers $n$ and $m$ ($5 \le n \le 400$, $4 \le m \le 400$).

翻译中…

Then $n$ lines follow, each line contains $m$ characters $0$ or $1$. If the $j$-th character of $i$-th line is $0$, block $A_{i,j}$ is an empty block. Otherwise, block $A_{i,j}$ is an obsidian block.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $400$.

翻译中…

It is guaranteed that the sum of $m$ over all test cases does not exceed $400$.

翻译中…

Output

翻译中…

Output $t$ answers, and each answer in a line.

翻译中…

Note

翻译中…

In the first test case, the final portal is like this:

翻译中…

1110
1001
1001
1001
0111

翻译中…

样例

Input #1
1
5 4
1000
0000
0110
0000
0001
Output #1
12
InputCopy OutputCopy
Input #2
1
9 9
001010001
101110100
000010011
100000001
101010101
110001111
000001111
111100000
000110000
Output #2
5
InputCopy OutputCopy
题目信息
题号
1580A
时间限制
1 s
内存限制
256 MB
标签
暴力
数据结构
动态规划
贪心
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。