結果

問題 No.943 取り調べ
ユーザー face4
提出日時 2019-11-14 22:10:48
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 669 bytes
コンパイル時間 299 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 17,696 KB
最終ジャッジ日時 2024-09-24 22:57:20
合計ジャッジ時間 7,673 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 7 TLE * 2 -- * 15
権限があれば一括ダウンロードができます

ソースコード

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