結果
| 問題 |
No.943 取り調べ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-11-14 22:27:58 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 501 ms / 1,206 ms |
| コード長 | 683 bytes |
| コンパイル時間 | 336 ms |
| コンパイル使用メモリ | 81,708 KB |
| 実行使用メモリ | 76,092 KB |
| 最終ジャッジ日時 | 2024-09-24 22:57:58 |
| 合計ジャッジ時間 | 3,653 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 24 |
ソースコード
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 = min(ans, tmp)
print(ans)