結果

問題 No.943 取り調べ
ユーザー mkawa2mkawa2
提出日時 2019-12-10 00:31:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 185 ms / 1,206 ms
コード長 1,128 bytes
コンパイル時間 332 ms
コンパイル使用メモリ 87,304 KB
実行使用メモリ 78,744 KB
最終ジャッジ日時 2023-09-05 14:33:58
合計ジャッジ時間 3,706 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,384 KB
testcase_01 AC 83 ms
71,160 KB
testcase_02 AC 74 ms
71,232 KB
testcase_03 AC 72 ms
71,508 KB
testcase_04 AC 127 ms
78,728 KB
testcase_05 AC 185 ms
78,548 KB
testcase_06 AC 181 ms
78,560 KB
testcase_07 AC 75 ms
71,488 KB
testcase_08 AC 131 ms
78,744 KB
testcase_09 AC 101 ms
77,192 KB
testcase_10 AC 98 ms
77,176 KB
testcase_11 AC 89 ms
76,352 KB
testcase_12 AC 71 ms
71,440 KB
testcase_13 AC 80 ms
75,716 KB
testcase_14 AC 84 ms
76,128 KB
testcase_15 AC 75 ms
71,304 KB
testcase_16 AC 76 ms
71,568 KB
testcase_17 AC 101 ms
77,172 KB
testcase_18 AC 74 ms
71,276 KB
testcase_19 AC 80 ms
76,160 KB
testcase_20 AC 72 ms
71,384 KB
testcase_21 AC 72 ms
71,400 KB
testcase_22 AC 95 ms
77,204 KB
testcase_23 AC 150 ms
78,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    inf = 10 ** 7
    n = int(input())
    xx = [int(input().replace(" ", "")[::-1], 2) for _ in range(n)]
    aa = LI()
    # print(xx)
    # 全員が白状するために必要な(嘘を含めた)白状したという情報がt
    t = 0
    for x in xx: t |= x
    # 白状したという情報sによるビットDP
    dp = [inf] * (1 << n)
    dp[0] = 0
    for s in range(1 << n):
        if s == t: break
        pre = dp[s]
        # 申し訳なさを感じない場合
        for i, x in enumerate(xx):
            if s & x == x:
                ns = s | 1 << i
                if pre < dp[ns]: dp[ns] = pre
        # 申し訳なさを感じる場合
        for i, a in enumerate(aa):
            ns = s | 1 << i
            if pre + a < dp[ns]: dp[ns] = pre + a
        # print(dp)
    print(dp[t])

main()
0