#P15712. [JAG 2023 Summer Camp #2] Fraises dans une boîte

[JAG 2023 Summer Camp #2] Fraises dans une boîte

题目描述

A box is divided into grids with HH rows and WW columns. Some squares contain strawberries.

The state of the box is denoted by SS, and Sx,y=1S_{x,y} = 1 means that the square in the xx-th row and yy-th column contains one strawberry. If Sx,y=0S_{x,y} = 0, the square in the xx-th row and yy-th column is empty.

Tomoe devised the following method to distinguish between these strawberries.

  • Let Ax,yA_{x,y} be defined as the sum of Si,jS_{i,j} for all integer pairs (i,j)(i,j) satisfying i=x,1jyi = x, 1 \leq j \leq y.
  • Let Bx,yB_{x,y} be defined as the sum of Si,jS_{i,j} for all integer pairs (i,j)(i,j) satisfying 1ix,j=y1 \leq i \leq x, j = y.
  • If the square in the xx-th row and yy-th column contains a strawberry, label the strawberry with the tuple (Ax,y,Bx,y)(A_{x,y}, B_{x,y}).

This method could result in multiple strawberries having the same label, and the strawberries could not be distinguished. Therefore, she decided to add some strawberries before labeling them.

More formally, for (x,y)(x,y) such that Sx,y=0S_{x,y} = 0, we operated Sx,y1S_{x,y} \leftarrow 1 any number of times greater than 00.

What is the minimum number of strawberries that must be added to label all the strawberries differently?

输入格式

$$\begin{aligned} &H \ W \\ &S_{1,1} \ S_{1,2} \ \ldots \ S_{1,W} \\ &S_{2,1} \ S_{2,2} \ \ldots \ S_{2,W} \\ &\vdots \\ &S_{H,1} \ S_{H,2} \ \ldots \ S_{H,W} \end{aligned} $$

The input satisfies the following constraints.

  • All inputs consist of integers.
  • 1H3001 \leq H \leq 300
  • 1W3001 \leq W \leq 300
  • 0Sx,y10 \leq S_{x,y} \leq 1

输出格式

Output the answer in one line. Add a new line at the end of the output.

3 2
1 0
0 1
0 1
1
4 4
0 1 1 1
1 1 1 0
1 0 1 1
1 0 1 0
2
5 5
0 0 1 0 1
0 1 0 1 0
0 0 1 0 1
0 1 0 1 0
0 0 1 0 1
8
1 1
0
0

提示

In Sample Input 1, Tomoe can achieve the condition by placing a strawberry in the upper right square.