結果

問題 No.1479 Matrix Eraser
ユーザー 小野寺健小野寺健
提出日時 2021-04-28 14:43:36
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,237 bytes
コンパイル時間 261 ms
コンパイル使用メモリ 10,912 KB
実行使用メモリ 19,744 KB
最終ジャッジ日時 2023-09-21 19:04:34
合計ジャッジ時間 6,080 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,340 KB
testcase_01 AC 17 ms
8,192 KB
testcase_02 AC 17 ms
8,416 KB
testcase_03 AC 16 ms
8,352 KB
testcase_04 AC 16 ms
8,232 KB
testcase_05 AC 17 ms
8,308 KB
testcase_06 AC 17 ms
8,296 KB
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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):
            matched[u] = v
            return True
    return False
    
def mpc(xn, yn):
    global matched, edges
    matched = [-1] * yn

    left = [len(s) > 0 for s in edges]
    right = [False] * yn

    ledges = []
    redges = matched

    for v in range(xn):
        if not dfs(v, set()):
            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 = dict()

    for i in range(H):
        for j, a in enumerate(list(map(int, input().split()))):
            if a > 0:
                if a not in S:
                    S[a] = []
                S[a].append((i, j))
                    
    
    cnt = 0
    for pairs in S.values():
        edges = [set() for _ in range(H)]
        for i, j in pairs:
            edges[i].add(j)
        n = mpc(H, W)
        cnt += n
    
    print(cnt)
0