結果

問題 No.943 取り調べ
ユーザー wgrapewgrape
提出日時 2023-12-11 10:36:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 680 ms / 1,206 ms
コード長 625 bytes
コンパイル時間 268 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 77,540 KB
最終ジャッジ日時 2023-12-11 10:37:02
合計ジャッジ時間 6,006 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,460 KB
testcase_01 AC 35 ms
53,460 KB
testcase_02 AC 35 ms
53,460 KB
testcase_03 AC 34 ms
53,460 KB
testcase_04 AC 680 ms
77,528 KB
testcase_05 AC 335 ms
77,540 KB
testcase_06 AC 357 ms
77,540 KB
testcase_07 AC 35 ms
53,460 KB
testcase_08 AC 668 ms
77,528 KB
testcase_09 AC 222 ms
75,992 KB
testcase_10 AC 229 ms
75,980 KB
testcase_11 AC 100 ms
75,728 KB
testcase_12 AC 34 ms
53,460 KB
testcase_13 AC 51 ms
64,316 KB
testcase_14 AC 52 ms
64,312 KB
testcase_15 AC 41 ms
59,628 KB
testcase_16 AC 35 ms
53,460 KB
testcase_17 AC 232 ms
75,980 KB
testcase_18 AC 41 ms
59,596 KB
testcase_19 AC 49 ms
64,312 KB
testcase_20 AC 43 ms
61,712 KB
testcase_21 AC 37 ms
53,460 KB
testcase_22 AC 250 ms
75,980 KB
testcase_23 AC 363 ms
77,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
X = [list(map(int,input().split())) for i in range(N)]
A = list(map(int,input().split()))
INF = 1 << 60
dp = [INF] * (1 << N)
dp[0] = 0

for status in range(1 << N):
    for target in range(N):
        if (status >> target) & 1:
            continue
        cost = 0
        for i in range(N):
            if (X[target][i] == 1) and (status >> i) & 1 == 0: # 頼りにしている人が自白していない
                cost = A[target] # うそをつく必要がある
        next_status = status | (1 << target)
        dp[next_status] = min(dp[next_status], dp[status] + cost)
        
print(dp[-1])
0