結果
問題 |
No.943 取り調べ
|
ユーザー |
|
提出日時 | 2019-11-14 21:50:18 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 958 bytes |
コンパイル時間 | 193 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 17,952 KB |
最終ジャッジ日時 | 2024-09-24 22:56:30 |
合計ジャッジ時間 | 2,969 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 4 TLE * 1 -- * 19 |
ソースコード
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)