結果

問題 No.1479 Matrix Eraser
ユーザー 小野寺健小野寺健
提出日時 2021-04-28 12:56:53
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,383 bytes
コンパイル時間 525 ms
コンパイル使用メモリ 11,028 KB
実行使用メモリ 69,704 KB
最終ジャッジ日時 2023-09-21 16:49:42
合計ジャッジ時間 53,405 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,500 KB
testcase_01 AC 19 ms
8,600 KB
testcase_02 AC 19 ms
8,572 KB
testcase_03 AC 19 ms
8,708 KB
testcase_04 WA -
testcase_05 AC 19 ms
8,724 KB
testcase_06 AC 19 ms
8,580 KB
testcase_07 AC 167 ms
15,248 KB
testcase_08 AC 279 ms
20,708 KB
testcase_09 AC 566 ms
33,768 KB
testcase_10 AC 1,076 ms
50,560 KB
testcase_11 AC 656 ms
37,316 KB
testcase_12 AC 212 ms
17,372 KB
testcase_13 AC 272 ms
20,648 KB
testcase_14 AC 217 ms
17,560 KB
testcase_15 AC 61 ms
10,532 KB
testcase_16 AC 239 ms
17,804 KB
testcase_17 AC 1,260 ms
62,960 KB
testcase_18 AC 1,267 ms
62,944 KB
testcase_19 AC 1,249 ms
62,972 KB
testcase_20 AC 1,252 ms
62,840 KB
testcase_21 AC 1,258 ms
62,836 KB
testcase_22 AC 1,269 ms
63,060 KB
testcase_23 AC 1,232 ms
62,960 KB
testcase_24 AC 1,246 ms
63,028 KB
testcase_25 AC 1,244 ms
63,052 KB
testcase_26 AC 1,253 ms
63,324 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 2,910 ms
36,464 KB
testcase_33 AC 2,913 ms
36,704 KB
testcase_34 AC 2,912 ms
36,512 KB
testcase_35 AC 2,921 ms
36,580 KB
testcase_36 AC 2,940 ms
36,700 KB
testcase_37 AC 84 ms
8,652 KB
testcase_38 AC 2,096 ms
30,832 KB
testcase_39 AC 1,409 ms
69,704 KB
testcase_40 AC 19 ms
8,572 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

def dfs(v, visited):
    global edges, matched
    for u in edges[v]:
        if u in visited:
            continue
        visited.add(u)
        if matched[u] == -1 or dfs(matched[u], visited) >= 0:
            matched[u] = v
            return u
    return -1
    
def mpc(xn, yn):
    global matched, edges
    matched = [-1] * yn

    left = [True] * xn
    right = [False] * yn

    ledges = []
    redges = [-1] * yn

    for v in range(xn):
        u = dfs(v, set()) 
        if u >= 0:
            redges[u] = v
        else:
            left[v] = False
            ledges.append(v)
    for v in ledges:
        for u in edges[v]:
            right[u] = True
            if redges[u] >= 0:
                left[redges[u]] = False

    return sum(left+right)


if __name__ == '__main__':
    H, W = map(int, input().split())

    S = defaultdict(list)

    for i in range(H):
        for j, a in enumerate(list(map(int, input().split()))):
            if a > 0:
                S[a].append((i, j))
    
    cnt = 0
    for a, l in S.items():
        h , w = set(), set()
        for i, j in l:
            h.add(i)
            w.add(j)
        h, w = list(h), list(w)
        edges = [set() for _ in range(len(h))]
        for i, j in l:
            edges[h.index(i)].add(w.index(j))
        cnt += mpc(len(h), len(w))
    
    print(cnt)
0