CF1720C.Corners

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given a matrix consisting of nn rows and mm columns. Each cell of this matrix contains 00 or 11.

Let's call a square of size 2×22 \times 2 without one corner cell an L-shape figure. In one operation you can take one L-shape figure, with at least one cell containing 11 and replace all numbers in it with zeroes.

Find the maximum number of operations that you can do with the given matrix.

你被给定一个由 nn 行和 mm 列组成的矩阵。该矩阵的每个单元格中包含数字 00 或 11。

我们将一个大小为 2×22 \times 2、且缺失一个角上单元格的正方形称为 L 形图形。在一次操作中,你可以选取一个 L 形图形(要求其中至少有一个单元格的值为 11),并将该 L 形图形内所有数字替换为 00。

求对给定矩阵最多可以执行多少次这样的操作。

输入格式

The first line contains one integer tt (1≤t≤5001 \leq t \leq 500) — the number of test cases. Then follow the descriptions of each test case.

The first line of each test case contains two integers nn and mm (2≤n,m≤5002 \leq n, m \leq 500) — the size of the matrix.

Each of the following nn lines contains a binary string of length mm — the description of the matrix.

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

第一行包含一个整数 tt(1≤t≤5001 \leq t \leq 500),表示测试用例的数量。随后是每个测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 mm(2≤n,m≤5002 \leq n, m \leq 500),表示矩阵的大小。

接下来的 nn 行,每行包含一个长度为 mm 的二进制字符串,用于描述该矩阵。

保证所有测试用例中 nn 的总和以及 mm 的总和均不超过 10001000。

输出格式

For each test case output the maximum number of operations you can do with the given matrix.

对于每个测试用例,输出在给定矩阵上所能执行的最大操作次数。

输入输出样例

  • 输入#1

    4
    4 3
    101
    111
    011
    110
    3 4
    1110
    0111
    0111
    2 2
    00
    00
    2 2
    11
    11

    输出#1

    8
    9
    0
    2

说明/提示

In the first testcase one of the optimal sequences of operations is the following (bold font shows l-shape figure on which operation was performed):

  • Matrix before any operation was performed:

    1

    0

    1

    1

    1

    1

    0

    1

    1

    1

    1

    0

  • Matrix after 11 operation was performed:

    1

    0

    0

    1

    0

    1

    0

    1

    1

    1

    1

    0

  • Matrix after 22 operations were performed:

    1

    0

    0

    1

    0

    0

    0

    1

    1

    1

    1

    0

  • Matrix after 33 operations were performed:

    1

    0

    0

    1

    0

    0

    0

    1

    0

    1

    1

    0

  • Matrix after 44 operations were performed:

    1

    0

    0

    0

    0

    0

    0

    1

    0

    1

    1

    0

  • Matrix after 55 operations were performed:

    1

    0

    0

    0

    0

    0

    0

    1

    0

    1

    0

    0

  • Matrix after 66 operations were performed:

    1

    0

    0

    0

    0

    0

    0

    0

    0

    1

    0

    0

  • Matrix after 77 operations were performed:

    0

    0

    0

    0

    0

    0

    0

    0

    0

    1

    0

    0

  • Matrix after 88 operations were performed:

    0

    0

    0

    0

    0

    0

    0

    0

    0

    0

    0

    0

In the third testcase from the sample we can not perform any operation because the matrix doesn't contain any ones.

In the fourth testcase it does not matter which L-shape figure we pick in our first operation. We will always be left with single one. So we will perform 22 operations.

在第一个测试用例中,一种最优的操作序列如下所示(加粗字体表示执行操作的 L 形区域):

  • 初始矩阵(尚未执行任何操作):

    1

    0

    1

    1

    1

    1

    0

    1

    1

    1

    1

    0

  • 执行 11 次操作后的矩阵:

    1

    0

    0

    1

    0

    1

    0

    1

    1

    1

    1

    0

  • 执行 22 次操作后的矩阵:

    1

    0

    0

    1

    0

    0

    0

    1

    1

    1

    1

    0

  • 执行 33 次操作后的矩阵:

    1

    0

    0

    1

    0

    0

    0

    1

    0

    1

    1

    0

  • 执行 44 次操作后的矩阵:

    1

    0

    0

    0

    0

    0

    0

    1

    0

    1

    1

    0

  • 执行 55 次操作后的矩阵:

    1

    0

    0

    0

    0

    0

    0

    1

    0

    1

    0

    0

  • 执行 66 次操作后的矩阵:

    1

    0

    0

    0

    0

    0

    0

    0

    0

    1

    0

    0

  • 执行 77 次操作后的矩阵:

    0

    0

    0

    0

    0

    0

    0

    0

    0

    1

    0

    0

  • 执行 88 次操作后的矩阵:

    0

    0

    0

    0

    0

    0

    0

    0

    0

    0

    0

    0

在样例中的第三个测试用例中,我们无法执行任何操作,因为该矩阵不包含任何数字 1。

在第四个测试用例中,第一次操作选择哪一个 L 形区域均无影响;操作后总会剩余一个 1。因此我们将总共执行 22 次操作。

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

首页