結果

問題 No.943 取り調べ
ユーザー tobusakanatobusakana
提出日時 2022-10-23 15:49:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 712 ms / 1,206 ms
コード長 998 bytes
コンパイル時間 301 ms
コンパイル使用メモリ 86,860 KB
実行使用メモリ 79,232 KB
最終ジャッジ日時 2023-09-15 02:03:31
合計ジャッジ時間 6,029 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,440 KB
testcase_01 AC 75 ms
71,404 KB
testcase_02 AC 75 ms
71,420 KB
testcase_03 AC 74 ms
71,528 KB
testcase_04 AC 712 ms
79,148 KB
testcase_05 AC 329 ms
79,056 KB
testcase_06 AC 330 ms
79,160 KB
testcase_07 AC 75 ms
71,628 KB
testcase_08 AC 701 ms
79,232 KB
testcase_09 AC 237 ms
77,976 KB
testcase_10 AC 230 ms
77,316 KB
testcase_11 AC 130 ms
77,324 KB
testcase_12 AC 77 ms
71,288 KB
testcase_13 AC 88 ms
76,452 KB
testcase_14 AC 89 ms
76,476 KB
testcase_15 AC 82 ms
76,088 KB
testcase_16 AC 74 ms
71,096 KB
testcase_17 AC 254 ms
77,500 KB
testcase_18 AC 80 ms
75,976 KB
testcase_19 AC 89 ms
76,500 KB
testcase_20 AC 83 ms
76,088 KB
testcase_21 AC 74 ms
71,460 KB
testcase_22 AC 265 ms
77,704 KB
testcase_23 AC 341 ms
78,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline
N = int(readline())

X = [int(readline().replace(" ","")[::-1],2) 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 # 自白済み。
#   print(bin(status)[2:].zfill(3),"から",bin(1 << target)[2:].zfill(3),"を自白させたい")
    # X[target]が1の人が自白済みでなければコストが掛かる
    cost = dp[status]
    next_status = status | (1 << target)
    for i in range(N):
      if (X[target] >> i) & 1 and (status >> i) & 1 == 0:# 信頼している人が自白していない
        # iの人が自白したと嘘をつく
#       print(i,"が自白したと嘘をつく",A[i])
        next_status |= (1 << i)
        cost += A[i]
#   print("cost",cost,"が発生")
    if dp[next_status] > cost:
      dp[next_status] = cost
      
print(dp[-1])
0