結果

問題 No.519 アイドルユニット
ユーザー 👑 rin204rin204
提出日時 2022-11-08 18:25:06
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,472 bytes
コンパイル時間 336 ms
コンパイル使用メモリ 87,116 KB
実行使用メモリ 76,344 KB
最終ジャッジ日時 2023-09-29 07:56:54
合計ジャッジ時間 4,882 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
76,080 KB
testcase_01 AC 84 ms
75,616 KB
testcase_02 AC 80 ms
75,416 KB
testcase_03 WA -
testcase_04 AC 74 ms
71,124 KB
testcase_05 AC 75 ms
71,268 KB
testcase_06 AC 73 ms
71,080 KB
testcase_07 AC 76 ms
71,252 KB
testcase_08 AC 74 ms
71,168 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 74 ms
71,104 KB
testcase_13 AC 75 ms
71,100 KB
testcase_14 AC 75 ms
71,252 KB
testcase_15 AC 74 ms
71,072 KB
testcase_16 AC 74 ms
71,296 KB
testcase_17 AC 74 ms
70,968 KB
testcase_18 AC 78 ms
75,180 KB
testcase_19 WA -
testcase_20 AC 76 ms
71,304 KB
testcase_21 AC 81 ms
75,184 KB
testcase_22 AC 76 ms
71,240 KB
testcase_23 AC 73 ms
71,076 KB
testcase_24 WA -
testcase_25 AC 81 ms
75,924 KB
testcase_26 AC 79 ms
75,824 KB
testcase_27 AC 80 ms
75,912 KB
testcase_28 WA -
testcase_29 AC 90 ms
76,104 KB
testcase_30 AC 81 ms
76,084 KB
testcase_31 AC 83 ms
75,940 KB
testcase_32 AC 87 ms
76,208 KB
testcase_33 AC 76 ms
71,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def hungarian(A):
    inf = 1 << 40
    n = len(A) + 1
    m = len(A[0]) + 1
    P = [0] * m
    way = [0] * m
    U = [0] * n
    V = [0] * m
    for i in range(1, n):
        P[0] = i
        minV = [inf] * m
        used = [False] * m
        j0 = 0
        while P[j0] != 0:
            i0 = P[j0]
            j1 = 0
            used[j0] = True
            delta = inf
            for j in range(1, m):
                if used[j]:
                    continue
                if i0 == 0 or j == 0:
                    cur =  -U[i0] - V[j]
                else:
                    cur = A[i0 - 1][j - 1] - U[i0] - V[j]
                if cur < minV[j]:
                    minV[j] = cur
                    way[j] = j0
                if minV[j] < delta:
                    delta = minV[j]
                    j1 = j
            for j in range(m):
                if used[j]:
                    U[P[j]] += delta
                    V[j] -= delta
                else:
                    minV[j] -= delta
            j0 = j1
        P[j0] = P[way[j0]]
        j0 = way[j0]
        while j0 != 0:
            P[j0] = P[way[j0]]
            j0 = way[j0]
    
    ret = [-1] * (n - 1)
    for i in range(1, m):
        if P[i] != 0:
            ret[P[i] - 1] = i - 1
    return -V[0], ret

n = int(input())
F = [list(map(int, input().split())) for _ in range(n)]
for i in range(n):
    for j in range(n):
        F[i][j] *= -1

ans = hungarian(F)[0]
print(-ans // 2)


0