結果

問題 No.943 取り調べ
ユーザー face4face4
提出日時 2019-11-14 22:13:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 181 ms / 1,206 ms
コード長 669 bytes
コンパイル時間 146 ms
コンパイル使用メモリ 81,824 KB
実行使用メモリ 75,576 KB
最終ジャッジ日時 2023-10-25 03:28:49
合計ジャッジ時間 2,475 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,616 KB
testcase_01 AC 36 ms
53,616 KB
testcase_02 AC 37 ms
53,616 KB
testcase_03 AC 36 ms
53,616 KB
testcase_04 AC 110 ms
75,480 KB
testcase_05 AC 89 ms
72,336 KB
testcase_06 AC 102 ms
73,952 KB
testcase_07 AC 39 ms
53,616 KB
testcase_08 AC 120 ms
75,516 KB
testcase_09 AC 82 ms
73,492 KB
testcase_10 AC 70 ms
70,524 KB
testcase_11 AC 73 ms
72,632 KB
testcase_12 AC 36 ms
53,616 KB
testcase_13 AC 45 ms
62,244 KB
testcase_14 AC 41 ms
60,108 KB
testcase_15 AC 36 ms
53,616 KB
testcase_16 AC 37 ms
53,616 KB
testcase_17 AC 79 ms
72,628 KB
testcase_18 AC 36 ms
53,616 KB
testcase_19 AC 45 ms
62,116 KB
testcase_20 AC 36 ms
53,616 KB
testcase_21 AC 36 ms
53,616 KB
testcase_22 AC 79 ms
72,604 KB
testcase_23 AC 181 ms
75,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())

counton = [0]*n
for i in range(n):
    b = input().split()
    for j in range(n):
            counton[i] += 1<<j if b[j]=="1" else 0

a = list(map(int, input().split()))

ans = sum(a)

for i in range(2**n):
    tmp = 0
    for j in range(n):
        tmp += a[j] if ((i>>j)&1) == 1 else 0
    
    # 高速化出来る
    if tmp >= ans:
        continue

    lie, confess, k = i, 0, -1
    while k+1 < n:
        k += 1
        if ((confess>>k)&1) == 1:
            continue
        if (lie&counton[k]) == counton[k]:
            confess |= 1<<k
            lie |= 1<<k
            k = -1
    
    if confess == (1<<n)-1:
        ans = tmp

print(ans)
0