結果

問題 No.943 取り調べ
ユーザー ああいいああいい
提出日時 2022-03-04 16:58:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 388 ms / 1,206 ms
コード長 874 bytes
コンパイル時間 577 ms
コンパイル使用メモリ 87,284 KB
実行使用メモリ 77,736 KB
最終ジャッジ日時 2023-09-25 17:18:29
合計ジャッジ時間 5,907 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,208 KB
testcase_01 AC 72 ms
71,364 KB
testcase_02 AC 71 ms
71,416 KB
testcase_03 AC 75 ms
71,368 KB
testcase_04 AC 388 ms
77,236 KB
testcase_05 AC 253 ms
77,244 KB
testcase_06 AC 258 ms
77,336 KB
testcase_07 AC 74 ms
71,568 KB
testcase_08 AC 368 ms
77,472 KB
testcase_09 AC 145 ms
77,472 KB
testcase_10 AC 171 ms
77,468 KB
testcase_11 AC 127 ms
77,728 KB
testcase_12 AC 72 ms
71,300 KB
testcase_13 AC 92 ms
76,872 KB
testcase_14 AC 97 ms
76,768 KB
testcase_15 AC 77 ms
75,960 KB
testcase_16 AC 72 ms
71,420 KB
testcase_17 AC 149 ms
77,564 KB
testcase_18 AC 75 ms
71,364 KB
testcase_19 AC 90 ms
76,672 KB
testcase_20 AC 79 ms
76,388 KB
testcase_21 AC 72 ms
71,192 KB
testcase_22 AC 151 ms
77,368 KB
testcase_23 AC 282 ms
77,736 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
X = [list(map(int,input().split())) for _ in range(N)]
A = list(map(int,input().split()))
G = [[] for _ in range(N)]
Gnum = [0] * N
for i in range(N):
    for j in range(N):
        if X[i][j]:
            G[j].append(i)
            Gnum[i] += 1
ans = 10 ** 8
for bit in range(1 << N):
    num = Gnum.copy()
    stack = []
    count = 0
    _sum = 0
    for i in range(N):
        if bit & (1 << i):
            _sum += A[i]
            stack.append(i)
            count += 1
            num[i] = 0
        else:
            if Gnum[i] == 0:
                stack.append(i)
                count += 1
    while stack:
        now = stack.pop()
        for v in G[now]:
            num[v] -= 1
            if num[v] == 0:
                stack.append(v)
                count += 1
    if count == N:
        if _sum <= ans:
            ans = _sum
print(ans)
0