No.3060 Erase Binary Matrix
Problem Statement
You are given a matrix $A$ with $H$ rows and $W$ columns.
Initially, the element in the $i$-th row and $j$-th column of the matrix $A$ is $A_{i,j}$. Here, $A_{i,j}$ is 0 or 1.
You may repeat any of the following operations, in any order and any number of times, until the matrix $A$ becomes an empty matrix.
- Operation $1$: Choose one row whose values are all the same, and delete that row.
- Operation $2$: Choose one column whose values are all the same, and delete that column.
- Operation $3$: Choose one row and delete it.
Find the minimum possible number of times operation $3$ is performed before the matrix $A$ becomes an empty matrix.
Input
$H\ W$
$A_{1,1}A_{1,2}\dots A_{1,W}$
$A_{1,1}A_{1,2}\dots A_{2,W}$
$\vdots$
$A_{H,1}A_{H,2}\dots A_{H,W}$
- $1 \le H,W \le 500$
- $A_{i,j}$ is
0or1
Output
Output the minimum possible number of times operation $3$ is performed. Print a newline at the end.
Sample
Sample 1
Input
4 3 101 111 010 010
Output
1
The matrix $A$ can be made empty by the following procedure.
- Perform operation $3$ on row $1$.
- Perform operation $1$ on row $1$.
- Perform operation $2$ on each column.
101 -> 111 -> 010 -> 10 -> 0 -> (空)
111 010 010 10 0
010 010
010
Sample 2
Input
4 4 1111 1000 1011 1010
Output
0
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
tute7627
SPD_9X2