問題一覧 > 通常問題

No.3060 Erase Binary Matrix

レベル : / AI推定難易度 : 1850 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 14
作問者 : 👑 tute7627 / テスター : 👑 rin204 SPD_9X2
お気に入りにしたユーザー ProblemId : 11516 / 自分の提出
問題文最終更新日: 2025-03-12 02:46:18
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 460 (順位表) の他の問題:

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 0 or 1

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.

  1. Perform operation $3$ on row $1$.
  2. Perform operation $1$ on row $1$.
  3. 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もしくは右上の雲マークをクリックしてアカウントを作成してください。