結果

問題 No.943 取り調べ
ユーザー OKCH3COOHOKCH3COOH
提出日時 2019-12-08 18:49:51
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 835 bytes
コンパイル時間 112 ms
コンパイル使用メモリ 10,880 KB
実行使用メモリ 210,496 KB
最終ジャッジ日時 2023-08-30 02:13:17
合計ジャッジ時間 3,722 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
13,088 KB
testcase_01 AC 20 ms
8,524 KB
testcase_02 AC 19 ms
8,660 KB
testcase_03 AC 19 ms
8,668 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 defaultdict

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

parents = [tuple(input().split()) for _ in range(N)]
A = list(map(int, input().split()))

masks = []
for mask in range(1 << N):
    V = set(i for i in range(N) if (mask & (1 << i)) != 0)
    masks.append(V)
masks.sort(key=lambda B: len(B))

dp = defaultdict(lambda : INF)
dp[()] = 0

for mask in masks:
    V = list(mask)
    V.sort()
    V = tuple(V)

    for d in range(N):
        if d in mask:
            continue

        cost = 0
        state = list(mask) + [d]
        for i, (s, a) in enumerate(zip(parents[d], A)):
            if s == '1' and (i not in mask):
                state.append(i)
                cost += a
        state.sort()
        state = tuple(state)
        dp[state] = min(dp[state], dp[V] + cost)

print(dp[tuple(i for i in range(N))])
0