結果
| 問題 |
No.943 取り調べ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-11-14 22:16:33 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 958 bytes |
| コンパイル時間 | 152 ms |
| コンパイル使用メモリ | 81,848 KB |
| 実行使用メモリ | 77,380 KB |
| 最終ジャッジ日時 | 2024-09-24 22:58:28 |
| 合計ジャッジ時間 | 9,168 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 22 TLE * 2 |
ソースコード
from collections import deque
N = int(input())
X = [list(map(int, input().split())) for i in range(N)]
A = [int(x) for x in input().split()]
def isGood(bit):
ink = [0] * N
expanded = [False] * N
for i in range(N):
for j in range(N):
if X[i][j]:
ink[i] += 1
Q = deque()
for i in range(N):
if bit & (1 << i):
ink[i] = 0
if ink[i] == 0:
Q.append(i)
while len(Q) > 0:
d = Q.popleft()
if expanded[d]:
continue
expanded[d] = True
for i in range(N):
if X[i][d] and (not expanded[i]):
ink[i] -= 1
if ink[i] == 0:
Q.append(i)
return expanded.count(True) == N
ans = 1e20
for bit in range(1 << N):
cost = 0
for i in range(N):
if bit & (1 << i):
cost += A[i]
if isGood(bit):
ans = min(ans, cost)
print(ans)