結果

問題 No.943 取り調べ
ユーザー mkawa2mkawa2
提出日時 2021-04-07 18:59:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 256 ms / 1,206 ms
コード長 1,183 bytes
コンパイル時間 575 ms
コンパイル使用メモリ 87,272 KB
実行使用メモリ 84,972 KB
最終ジャッジ日時 2023-09-05 02:45:11
合計ジャッジ時間 4,725 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,312 KB
testcase_01 AC 68 ms
71,348 KB
testcase_02 AC 69 ms
71,060 KB
testcase_03 AC 68 ms
71,368 KB
testcase_04 AC 226 ms
82,984 KB
testcase_05 AC 256 ms
84,972 KB
testcase_06 AC 247 ms
84,432 KB
testcase_07 AC 69 ms
71,184 KB
testcase_08 AC 221 ms
83,196 KB
testcase_09 AC 130 ms
78,084 KB
testcase_10 AC 129 ms
78,108 KB
testcase_11 AC 102 ms
77,788 KB
testcase_12 AC 73 ms
71,352 KB
testcase_13 AC 81 ms
76,292 KB
testcase_14 AC 88 ms
76,276 KB
testcase_15 AC 71 ms
71,144 KB
testcase_16 AC 69 ms
71,408 KB
testcase_17 AC 126 ms
78,164 KB
testcase_18 AC 70 ms
71,484 KB
testcase_19 AC 79 ms
76,140 KB
testcase_20 AC 70 ms
71,348 KB
testcase_21 AC 70 ms
71,284 KB
testcase_22 AC 123 ms
78,380 KB
testcase_23 AC 243 ms
83,736 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10**6)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.buffer.readline())
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def LI1(): return list(map(int1, sys.stdin.buffer.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def BI(): return sys.stdin.buffer.readline().rstrip()
def SI(): return sys.stdin.buffer.readline().rstrip().decode()
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
dij = [(0, 1), (1, 0), (1, 1), (1, -1)]
inf = 10**19
# md = 998244353
md = 10**9+7

n = II()
ss = []
for _ in range(n):
    s = SI()
    s = s.replace(" ", "")
    ss.append(int(s[::-1], 2))
aa = LI()

def chmin(bit, val):
    if val < dp[bit]: dp[bit] = val

dp = [inf]*(1 << n)
dp[0] = 0
for bit in range(1 << n):
    pre = dp[bit]
    for i, s in enumerate(ss):
        if bit >> i & 1: continue
        nbit = bit | 1 << i
        if s & bit == s: chmin(nbit, pre)
        else: chmin(nbit, pre+aa[i])

print(dp[-1])
0