結果

問題 No.943 取り調べ
ユーザー ganariyaganariya
提出日時 2019-11-14 22:16:33
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 958 bytes
コンパイル時間 169 ms
コンパイル使用メモリ 81,816 KB
実行使用メモリ 76,712 KB
最終ジャッジ日時 2023-10-25 03:29:30
合計ジャッジ時間 9,702 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
55,576 KB
testcase_01 AC 43 ms
55,576 KB
testcase_02 AC 42 ms
55,576 KB
testcase_03 AC 42 ms
55,576 KB
testcase_04 TLE -
testcase_05 AC 1,092 ms
76,148 KB
testcase_06 AC 1,095 ms
76,152 KB
testcase_07 AC 41 ms
55,584 KB
testcase_08 TLE -
testcase_09 AC 348 ms
76,536 KB
testcase_10 AC 337 ms
76,580 KB
testcase_11 AC 252 ms
76,560 KB
testcase_12 AC 41 ms
55,584 KB
testcase_13 AC 85 ms
76,260 KB
testcase_14 AC 94 ms
76,316 KB
testcase_15 AC 56 ms
66,200 KB
testcase_16 AC 42 ms
55,584 KB
testcase_17 AC 389 ms
76,532 KB
testcase_18 AC 50 ms
61,956 KB
testcase_19 AC 86 ms
76,260 KB
testcase_20 AC 58 ms
66,060 KB
testcase_21 AC 42 ms
55,584 KB
testcase_22 AC 430 ms
76,504 KB
testcase_23 AC 1,005 ms
76,612 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

N = int(input())
X = [list(map(int, input().split())) for i in range(N)]
A = [int(x) for x in input().split()]


def isGood(bit):
    ink = [0] * N
    expanded = [False] * N
    for i in range(N):
        for j in range(N):
            if X[i][j]:
                ink[i] += 1

    Q = deque()
    for i in range(N):
        if bit & (1 << i):
            ink[i] = 0
        if ink[i] == 0:
            Q.append(i)

    while len(Q) > 0:
        d = Q.popleft()
        if expanded[d]:
            continue
        expanded[d] = True

        for i in range(N):
            if X[i][d] and (not expanded[i]):
                ink[i] -= 1
                if ink[i] == 0:
                    Q.append(i)

    return expanded.count(True) == N


ans = 1e20

for bit in range(1 << N):
    cost = 0
    for i in range(N):
        if bit & (1 << i):
            cost += A[i]
    if isGood(bit):
        ans = min(ans, cost)

print(ans)
0