CF1580A.Portal

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

CQXYM found a rectangle AA of size n×mn \times m. There are nn rows and mm 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 MM size of a×ba \times b is called a portal if and only if it satisfies the following conditions:

  • a≥5,b≥4a \geq 5,b \geq 4.
  • For all 1<x<a1 \lt x \lt a, blocks Mx,1M_{x,1} and Mx,bM_{x,b} are obsidian blocks.
  • For all 1<x<b1 \lt x \lt b, blocks M1,xM_{1,x} and Ma,xM_{a,x} are obsidian blocks.
  • For all 1<x<a,1<y<b1 \lt x \lt a,1 \lt y \lt b, block Mx,yM_{x,y} is an empty block.
  • M1,1,M1,b,Ma,1,Ma,bM_{1, 1}, M_{1, b}, M_{a, 1}, M_{a, b} can be any type.

Note that the there must be aa rows and bb columns, not bb rows and aa 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.

CQXYM 发现了一个大小为 n×mn \times m 的矩形 AA。该矩形共有 nn 行和 mm 列方块。每个方块要么是黑曜石方块,要么是空方块。CQXYM 每次操作可以将一个黑曜石方块变为一个空方块,或将一个空方块变为一个黑曜石方块。

一个大小为 a×ba \times b 的矩形 MM 被称为“传送门”(portal),当且仅当它满足以下条件:

  • a≥5, b≥4a \geq 5,\ b \geq 4。
  • 对所有 1<x<a1 \lt x \lt a,方块 Mx,1M_{x,1} 和 Mx,bM_{x,b} 均为黑曜石方块。
  • 对所有 1<x<b1 \lt x \lt b,方块 M1,xM_{1,x} 和 Ma,xM_{a,x} 均为黑曜石方块。
  • 对所有 1<x<a, 1<y<b1 \lt x \lt a,\ 1 \lt y \lt b,方块 Mx,yM_{x,y} 均为空方块。
  • 方块 M1,1, M1,b, Ma,1, Ma,bM_{1, 1},\ M_{1, b},\ M_{a, 1},\ M_{a, b} 可以是任意类型(黑曜石或空)。

注意:该矩形必须有 aa 行和 bb 列,而非 bb 行和 aa 列。

注意:四个角(即上述第 5 条中提到的方块)可以是任意类型。

CQXYM 想知道:使原矩形中至少存在一个子矩形是传送门所需的最少操作次数。

输入格式

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

For each test case, the first line contains two integers nn and mm (5≤n≤4005 \le n \le 400, 4≤m≤4004 \le m \le 400).

Then nn lines follow, each line contains mm characters 00 or 11. If the jj-th character of ii-th line is 00, block Ai,jA_{i,j} is an empty block. Otherwise, block Ai,jA_{i,j} is an obsidian block.

It is guaranteed that the sum of nn over all test cases does not exceed 400400.

It is guaranteed that the sum of mm over all test cases does not exceed 400400.

第一行包含一个整数 tt(t≥1t \geq 1),表示测试用例的数量。

对于每个测试用例,第一行包含两个整数 nn 和 mm(5≤n≤4005 \le n \le 400,4≤m≤4004 \le m \le 400)。

接下来是 nn 行,每行包含 mm 个字符,每个字符为 00 或 11。若第 ii 行的第 jj 个字符为 00,则方块 Ai,jA_{i,j} 为空方块;否则,方块 Ai,jA_{i,j} 为黑曜石方块。

保证所有测试用例的 nn 之和不超过 400400。

保证所有测试用例的 mm 之和不超过 400400。

输出格式

Output tt answers, and each answer in a line.

输出 tt 个答案,每个答案占一行。

输入输出样例

  • 输入#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:

1110
1001
1001
1001
0111

在第一个测试用例中,最终的传送门如下所示:

1110
1001
1001
1001
0111

输入解题思路,AI测评打分。不知道怎么写?

首页