Codeforces Round 815 (Div. 2)
C
Corners
Codeforces
1200
原题
← BD1 →
翻译中…

You are given a matrix consisting of $n$ rows and $m$ columns. Each cell of this matrix contains $0$ or $1$.

翻译中…

Let's call a square of size $2 \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 $1$ and replace all numbers in it with zeroes.

翻译中…

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

翻译中…

Input

翻译中…

The first line contains one integer $t$ ($1 \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 $n$ and $m$ ($2 \leq n, m \leq 500$) — the size of the matrix.

翻译中…

Each of the following $n$ lines contains a binary string of length $m$ — the description of the matrix.

翻译中…

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

翻译中…

Output

翻译中…

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

翻译中…

Note

翻译中…

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: 101111011110
  • Matrix after $1$ operation was performed: 10****0101011110
  • Matrix after $2$ operations were performed: 10010****0011110
  • Matrix after $3$ operations were performed: 10010****0010110
  • Matrix after $4$ operations were performed: 1000****00010110
  • Matrix after $5$ operations were performed: 10000001010****0
  • Matrix after $6$ operations were performed: 10000000****0100
  • Matrix after $7$ operations were performed: 0****00000000100
  • Matrix after $8$ operations were performed: 0000000000****00
翻译中…

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 $2$ operations.

翻译中…

样例

Input #1
4
4 3
101
111
011
110
3 4
1110
0111
0111
2 2
00
00
2 2
11
11
Output #1
8
9
0
2
InputCopy OutputCopy
题目信息
题号
1720C
时间限制
1 s
内存限制
256 MB
标签
贪心
模拟

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