結果

問題 No.943 取り調べ
ユーザー mkawa2mkawa2
提出日時 2019-12-10 00:30:33
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,121 ms / 1,206 ms
コード長 1,128 bytes
コンパイル時間 510 ms
コンパイル使用メモリ 10,876 KB
実行使用メモリ 18,228 KB
最終ジャッジ日時 2023-09-05 14:32:53
合計ジャッジ時間 8,715 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
7,884 KB
testcase_01 AC 16 ms
7,776 KB
testcase_02 AC 16 ms
7,752 KB
testcase_03 AC 16 ms
7,740 KB
testcase_04 AC 988 ms
18,228 KB
testcase_05 AC 1,113 ms
9,984 KB
testcase_06 AC 1,121 ms
10,124 KB
testcase_07 AC 17 ms
7,868 KB
testcase_08 AC 901 ms
9,988 KB
testcase_09 AC 244 ms
10,620 KB
testcase_10 AC 239 ms
10,620 KB
testcase_11 AC 121 ms
9,260 KB
testcase_12 AC 16 ms
7,752 KB
testcase_13 AC 17 ms
7,780 KB
testcase_14 AC 18 ms
8,176 KB
testcase_15 AC 16 ms
7,880 KB
testcase_16 AC 16 ms
7,756 KB
testcase_17 AC 218 ms
8,460 KB
testcase_18 AC 16 ms
7,784 KB
testcase_19 AC 17 ms
7,824 KB
testcase_20 AC 16 ms
7,836 KB
testcase_21 AC 16 ms
7,784 KB
testcase_22 AC 235 ms
10,696 KB
testcase_23 AC 1,082 ms
16,352 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