結果

問題 No.943 取り調べ
ユーザー ganariyaganariya
提出日時 2019-11-14 21:56:06
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,000 bytes
コンパイル時間 752 ms
コンパイル使用メモリ 11,740 KB
実行使用メモリ 10,304 KB
最終ジャッジ日時 2023-10-25 03:27:35
合計ジャッジ時間 3,988 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,304 KB
testcase_01 AC 31 ms
10,168 KB
testcase_02 AC 31 ms
10,168 KB
testcase_03 AC 31 ms
10,168 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
from copy import deepcopy

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

INK = [0] * N
for i in range(N):
    for j in range(N):
        if X[i][j]:
            INK[i] += 1


def isGood(bit):
    ink = deepcopy(INK)
    expanded = [False] * N

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

    while Q:
        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 and not expanded[i]:
                    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