結果
問題 |
No.1479 Matrix Eraser
|
ユーザー |
|
提出日時 | 2021-04-16 21:13:21 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,265 bytes |
コンパイル時間 | 169 ms |
コンパイル使用メモリ | 82,252 KB |
実行使用メモリ | 118,912 KB |
最終ジャッジ日時 | 2024-07-03 00:20:57 |
合計ジャッジ時間 | 12,820 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 23 WA * 2 TLE * 1 -- * 13 |
ソースコード
from collections import defaultdict h,w = map(int,input().split()) A = [list(map(int,input().split())) for i in range(h)] xy = [[] for i in range(5*10**5+5)] for i in range(h): for j in range(w): xy[A[i][j]].append((i,j)) ans = 0 for i in range(5*10**5,0,-1): if xy[i] == []: continue dich = defaultdict(int) dicw = defaultdict(int) for x,y in xy[i]: dich[x] += 1 dicw[y] += 1 dels = set() while True: mh = 0 ih = 0 mw = 0 iw = 0 for k,v in dich.items(): if v > mh: mh = v ih = k for k,v in dicw.items(): if v > mw: mw = v iw = k if mh == mw == 0: break ans += 1 if mh >= mw: dich[ih] = 0 for x,y in xy[i]: if (x,y) in dels: continue if x == ih: dicw[y] -= 1 dels.add((x,y)) else: dicw[iw] = 0 for x,y in xy[i]: if (x,y) in dels: continue if y == iw: dich[x] -= 1 dels.add((x,y)) print(ans)