結果

問題 No.1479 Matrix Eraser
ユーザー 小野寺健
提出日時 2021-04-27 18:35:09
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 790 bytes
コンパイル時間 142 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 42,684 KB
最終ジャッジ日時 2024-07-06 14:02:39
合計ジャッジ時間 7,887 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 8 TLE * 1 -- * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

H, W = map(int, input().split())

S = []

for i in range(H):
    for j, a in enumerate(list(map(int, input().split()))):
        if a > 0:
            S.append((a, i, j))
            
S.sort(reverse=True)

cnt = 0
while len(S) > 0:
    A = []
    A.append(S.pop(0))
    while len(S) > 0 and A[0][0] == S[0][0]:
        A.append(S.pop(0))
    Q = [(A, 1)]
    while len(Q) > 0:
        B, n = Q.pop(0)
        I = []
        for b in B[1:]:
            if B[0][1] != b[1]:
                I.append(b)
        if len(I) == 0:
            cnt += n
            break
        Q.append((I, n+1))
        J = []
        for b in B[1:]:
            if B[0][2] != b[2]:
                J.append(b)
        if len(J) == 0:
            cnt += n
            break
        Q.append((J, n+1))

print(cnt)
0