結果
問題 | No.943 取り調べ |
ユーザー | ganariya |
提出日時 | 2019-11-14 22:15:38 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,000 bytes |
コンパイル時間 | 943 ms |
コンパイル使用メモリ | 81,716 KB |
実行使用メモリ | 84,276 KB |
最終ジャッジ日時 | 2023-10-25 03:29:50 |
合計ジャッジ時間 | 10,904 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 48 ms
61,048 KB |
testcase_01 | AC | 46 ms
61,048 KB |
testcase_02 | AC | 48 ms
61,048 KB |
testcase_03 | AC | 48 ms
61,048 KB |
testcase_04 | TLE | - |
testcase_05 | TLE | - |
testcase_06 | TLE | - |
testcase_07 | AC | 47 ms
61,076 KB |
testcase_08 | TLE | - |
testcase_09 | AC | 389 ms
79,824 KB |
testcase_10 | AC | 378 ms
79,228 KB |
testcase_11 | AC | 268 ms
78,448 KB |
testcase_12 | AC | 46 ms
61,076 KB |
testcase_13 | AC | 93 ms
76,920 KB |
testcase_14 | AC | 98 ms
77,168 KB |
testcase_15 | AC | 55 ms
66,220 KB |
testcase_16 | AC | 45 ms
61,076 KB |
testcase_17 | AC | 407 ms
79,292 KB |
testcase_18 | AC | 51 ms
63,616 KB |
testcase_19 | AC | 92 ms
76,936 KB |
testcase_20 | AC | 57 ms
65,828 KB |
testcase_21 | AC | 48 ms
61,076 KB |
testcase_22 | AC | 426 ms
79,740 KB |
testcase_23 | TLE | - |
ソースコード
from collections import deque from copy import deepcopy N = int(input()) X = [list(map(int, input().split())) for i in range(N)] A = [int(x) for x in input().split()] INK = [0] * N for i in range(N): for j in range(N): if X[i][j]: INK[i] += 1 def isGood(bit): ink = deepcopy(INK) expanded = [False] * N Q = deque() for i in range(N): if bit & (1 << i): ink[i] = 0 if ink[i] == 0: Q.append(i) while Q: 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 and not expanded[i]: 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)