No.2473 Fraises dans une boîte
Problem Statement
There is a box divided into a grid of cells with $H$ rows and $W$ columns. It contains some strawberries.
The state of the box is represented by $S$. If $S_{x,y} = 1$, the cell in row $x$, column $y$ contains 1 strawberry. If $S_{x,y} = 0$, the cell in row $x$, column $y$ is empty.
Tomoe came up with the following method to distinguish these strawberries.
- Define $A_{x,y}$ as the sum of $S_{i,j}$ over all pairs of integers $(i,j)$ satisfying $i = x, 1 \le j \le y$.
- Define $B_{x,y}$ as the sum of $S_{i,j}$ over all pairs of integers $(i,j)$ satisfying $1 \le i \le x, j = y$.
- If a strawberry exists in the cell in row $x$, column $y$, label that strawberry with the tuple $(A_{x,y},B_{x,y})$.
However, with this method, multiple strawberries may receive the same label, making them indistinguishable from each other. Therefore, she decided to add some strawberries before labeling.
More formally, she performed the operation of setting $S_{x,y} \leftarrow 1$ for some $(x,y)$ with $S_{x,y} = 0$, any number of times (0 or more).
What is the minimum number of strawberries she must add so that, when the labeling is done afterward, all strawberries receive pairwise distinct labels?
Input
$H\ W$
$S_{1,1}\ S_{1,2}\ ...\ S_{1,W}$
$S_{2,1}\ S_{2,2}\ ...\ S_{2,W}$
$\vdots$
$S_{H,1}\ S_{H,2}\ ...\ S_{H,W}$
- All inputs are integers.
- $1 \le H \le 300$
- $1 \le W \le 300$
- $0 \le S_{x,y} \le 1$
Output
Output the answer on 1 line.
Print a newline at the end.
Sample
Sample 1
Input
3 2 1 0 0 1 0 1
Output
1
This can be achieved by placing a strawberry in the top-right cell.
Sample 2
Input
4 4 0 1 1 1 1 1 1 0 1 0 1 1 1 0 1 0
Output
2
Sample 3
Input
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
Output
8
Sample 4
Input
1 1 0
Output
0
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
SPD_9X2
akakimidori
りあん
tsutaj
beet
tute7627
nok0
だれ
momoyuu