問題一覧 > 通常問題

No.1479 Matrix Eraser

レベル : / AI推定難易度 : 2100 / 実行時間制限 : 1ケース 3.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 112
作問者 : fairy_lettuce / テスター : ngtkana nok0 ygussany PCTprobability
お気に入りにしたユーザー ProblemId : 5676 / 自分の提出
問題文最終更新日: 2021-04-11 14:04:35
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 291 (順位表) の他の問題:

Problem Statement

You are given a matrix $A$ with $H$ rows and $W$ columns. The element in row $i$ and column $j$ of this matrix is denoted by $A_{i,j}$.

You may perform the following operations any number of times, $0$ or more, in any order.

  • Choose the $i$-th row of the matrix $A$. Then, among the elements in the $i$-th row of $A$, all elements equal to the maximum value of the elements in the $i$-th row of $A$ are set to $0$.
  • Choose the $j$-th column of the matrix $A$. Then, among the elements in the $j$-th column of $A$, all elements equal to the maximum value of the elements in the $j$-th column of $A$ are set to $0$.

Your goal is to make all elements of the matrix $A$ equal to $0$. Find the minimum number of operations required to achieve the goal.

Input

$H\ W$
$A_{1,1}\ A_{1,2}\ \dots\ A_{1,W}$
$A_{2,1}\ A_{2,2}\ \dots\ A_{2,W}$
$\vdots$
$A_{H,1}\ A_{H,2}\ \dots\ A_{H,W}$

Constraints

  • $1\le H,\ W\le 500$
  • $0\le A_{ij}\le 5\times 10^5$
  • All input values are integers.

Output

Output the minimum number of operations required as an integer. Print a newline at the end.

Sample

Sample 1
Input
3 3
2 0 3
0 3 3
1 1 1
Output
4

For example, all elements of the matrix can be made $0$ by the following procedure.

  • Apply the operation to row $2$.
  • Apply the operation to row $3$.
  • Apply the operation to column $1$.
  • Apply the operation to column $3$.

Sample 2
Input
7 6
19 26 0 10 27 7
10 5 0 4 6 29
9 26 21 12 30 29
23 4 25 2 13 8
16 7 28 12 6 21
8 17 13 21 3 26
27 3 12 9 7 19
Output
36

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。