結果

問題 No.943 取り調べ
ユーザー OKCH3COOHOKCH3COOH
提出日時 2019-12-08 19:06:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 634 ms / 1,206 ms
コード長 761 bytes
コンパイル時間 344 ms
コンパイル使用メモリ 86,948 KB
実行使用メモリ 77,832 KB
最終ジャッジ日時 2023-08-30 02:34:30
合計ジャッジ時間 6,284 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,040 KB
testcase_01 AC 71 ms
71,188 KB
testcase_02 AC 70 ms
71,112 KB
testcase_03 AC 74 ms
71,004 KB
testcase_04 AC 417 ms
77,232 KB
testcase_05 AC 616 ms
77,244 KB
testcase_06 AC 634 ms
76,988 KB
testcase_07 AC 73 ms
71,156 KB
testcase_08 AC 421 ms
77,716 KB
testcase_09 AC 196 ms
77,832 KB
testcase_10 AC 184 ms
77,056 KB
testcase_11 AC 139 ms
77,384 KB
testcase_12 AC 72 ms
71,280 KB
testcase_13 AC 88 ms
76,612 KB
testcase_14 AC 91 ms
76,556 KB
testcase_15 AC 75 ms
75,880 KB
testcase_16 AC 71 ms
71,108 KB
testcase_17 AC 177 ms
77,276 KB
testcase_18 AC 73 ms
71,216 KB
testcase_19 AC 84 ms
76,648 KB
testcase_20 AC 73 ms
71,160 KB
testcase_21 AC 71 ms
71,284 KB
testcase_22 AC 168 ms
77,156 KB
testcase_23 AC 606 ms
77,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
INF = 10**10

parent = []
for _ in range(N):
    state = 0
    for i, s in enumerate(input().split()):
        if s == '1':
            state |= (1 << i)
    parent.append(state)
A = tuple(map(int, input().split()))

ans = INF
for mask in range(1 << N):
    state = mask
    V = set(range(N))

    while True:
        W = set()
        for v in V:
            if (parent[v] & state) == parent[v]:
                state |= (1 << v)
            else:
                W.add(v)
        if W == V:
            break
        V = W
        if len(V) == 0:
            cost = 0
            for i, a in enumerate(A):
                if (mask & (1 << i)) != 0:
                    cost += a
            ans = min(ans, cost)
            break

print(ans)
0