結果

問題 No.943 取り調べ
ユーザー OKCH3COOHOKCH3COOH
提出日時 2019-12-08 18:50:05
言語 PyPy3
(7.3.13)
結果
TLE  
実行時間 -
コード長 835 bytes
コンパイル時間 1,411 ms
コンパイル使用メモリ 86,908 KB
実行使用メモリ 230,628 KB
最終ジャッジ日時 2023-08-30 02:13:56
合計ジャッジ時間 3,600 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
75,872 KB
testcase_01 AC 92 ms
71,704 KB
testcase_02 AC 90 ms
71,544 KB
testcase_03 AC 94 ms
71,652 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