A14666 | Portal
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 < x < a$ , blocks $M_{x,1}$ and $M_{x,b}$ are obsidian blocks.
- For all $1 < x < b$ , blocks $M_{1,x}$ and $M_{a,x}$ are obsidian blocks.
- For all $1<x<a,1<y<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.
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 < x < a$ , blocks $M_{x,1}$ and $M_{x,b}$ are obsidian blocks.
- For all $1 < x < b$ , blocks $M_{1,x}$ and $M_{a,x}$ are obsidian blocks.
- For all $1<x<a,1<y<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.
输入格式
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$ .
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 $t$ answers, and each answer in a line.
输入输出样例
输入 #1
1 5 4 1000 0000 0110 0000 0001
输出 #1
12
输入 #2
1 9 9 001010001 101110100 000010011 100000001 101010101 110001111 000001111 111100000 000110000
输出 #2
5
In the first test case, the final portal is like this:
```
<pre class="verbatim"><br></br>1110<br></br>1001<br></br>1001<br></br>1001<br></br>0111<br></br>
```
```
<pre class="verbatim"><br></br>1110<br></br>1001<br></br>1001<br></br>1001<br></br>0111<br></br>
```
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted