結果

問題 No.943 取り調べ
ユーザー neterukunneterukun
提出日時 2019-12-21 10:23:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 683 ms / 1,206 ms
コード長 597 bytes
コンパイル時間 624 ms
コンパイル使用メモリ 87,168 KB
実行使用メモリ 77,524 KB
最終ジャッジ日時 2023-09-26 06:23:28
合計ジャッジ時間 6,995 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,340 KB
testcase_01 AC 74 ms
71,316 KB
testcase_02 AC 74 ms
71,416 KB
testcase_03 AC 74 ms
71,352 KB
testcase_04 AC 474 ms
77,048 KB
testcase_05 AC 680 ms
76,944 KB
testcase_06 AC 683 ms
76,912 KB
testcase_07 AC 74 ms
71,424 KB
testcase_08 AC 474 ms
77,212 KB
testcase_09 AC 199 ms
77,092 KB
testcase_10 AC 185 ms
77,112 KB
testcase_11 AC 136 ms
77,332 KB
testcase_12 AC 73 ms
71,420 KB
testcase_13 AC 89 ms
76,624 KB
testcase_14 AC 92 ms
76,532 KB
testcase_15 AC 81 ms
76,380 KB
testcase_16 AC 74 ms
71,344 KB
testcase_17 AC 196 ms
77,288 KB
testcase_18 AC 78 ms
75,760 KB
testcase_19 AC 91 ms
76,516 KB
testcase_20 AC 81 ms
76,288 KB
testcase_21 AC 73 ms
71,360 KB
testcase_22 AC 197 ms
77,416 KB
testcase_23 AC 677 ms
77,524 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
x = [list(map(int, input().split())) for i in range(n)]
a = list(map(int, input().split()))

bit_state = [0] * n
for i in range(n):
    for j in range(n):
        if x[i][j] == 1:
            bit_state[i] += 2 ** j

ans = 10**9
for bit_mask in range(1 << n):
    tmp_ans = 0
    tmp = bit_mask
    for i in range(n):
        if (bit_mask >> i) & 1:
            tmp_ans += a[i]
    for _ in range(n):
        for i in range(n):
            if tmp & bit_state[i] == bit_state[i]:
                tmp |= (1 << i)
    if tmp == (1 << n) - 1:
        ans = min(ans, tmp_ans)
print(ans)
0