結果

問題 No.943 取り調べ
ユーザー mkawa2mkawa2
提出日時 2021-04-07 18:29:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 591 ms / 1,206 ms
コード長 1,347 bytes
コンパイル時間 1,437 ms
コンパイル使用メモリ 86,548 KB
実行使用メモリ 80,404 KB
最終ジャッジ日時 2023-09-05 02:10:23
合計ジャッジ時間 8,558 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
71,468 KB
testcase_01 AC 76 ms
71,344 KB
testcase_02 AC 76 ms
71,284 KB
testcase_03 AC 75 ms
71,472 KB
testcase_04 AC 508 ms
78,764 KB
testcase_05 AC 279 ms
77,748 KB
testcase_06 AC 272 ms
78,036 KB
testcase_07 AC 81 ms
70,976 KB
testcase_08 AC 591 ms
80,404 KB
testcase_09 AC 310 ms
79,920 KB
testcase_10 AC 235 ms
78,948 KB
testcase_11 AC 255 ms
79,780 KB
testcase_12 AC 78 ms
71,360 KB
testcase_13 AC 92 ms
75,936 KB
testcase_14 AC 104 ms
76,056 KB
testcase_15 AC 79 ms
71,376 KB
testcase_16 AC 80 ms
71,208 KB
testcase_17 AC 293 ms
79,208 KB
testcase_18 AC 75 ms
71,420 KB
testcase_19 AC 99 ms
76,244 KB
testcase_20 AC 82 ms
71,204 KB
testcase_21 AC 81 ms
71,208 KB
testcase_22 AC 307 ms
79,372 KB
testcase_23 AC 591 ms
79,448 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 u in range(n):
    s = SI()
    s = s.replace(" ", "")
    ss.append(int(s[::-1], 2))
aa = LI()

def ok(bit):
    us = [(u, s) for u, s in enumerate(ss)]
    for _ in range(n):
        nus = []
        ln=len(us)
        for u, s in us:
            if bit & s == s: bit |= 1 << u
            else: nus.append((u, s))
        if not nus: return True
        us = nus
        if ln==len(us):return False
    return False

ans = inf
for bit in range(1 << n):
    cost = sum(aa[u] for u in range(n) if bit >> u & 1)
    if cost >= ans: continue
    if ok(bit): ans = cost

print(ans)
0