結果

問題 No.943 取り調べ
ユーザー ttrttr
提出日時 2020-02-21 17:52:07
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 824 bytes
コンパイル時間 104 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 16,256 KB
最終ジャッジ日時 2024-04-17 06:48:17
合計ジャッジ時間 4,395 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
16,256 KB
testcase_01 AC 30 ms
10,880 KB
testcase_02 AC 31 ms
10,880 KB
testcase_03 AC 31 ms
11,008 KB
testcase_04 TLE -
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
X = [[int(x) for x in input().split()] for _ in range(N)]
A = [int(a) for a in input().split()]

par = [set([]) for _ in range(N)]
for i in range(N):
    for j in range(N):
        if X[i][j] == 1:
            par[i].add(j)

dp = [-1]*(2**N)
dp[-1] = 1
def f(n):
    if dp[n] >= 0:
        return dp[n]
    S = set([])
    for j in range(N):
        if n & (1<<j):
            S.add(j)
    for i in range(N):
        if par[i] <= S:
            S.add(i)
    m = 0
    for j in range(N):
        if j in S:
            m += 1<<j
    if m == n:
        dp[n] = 0
    else:
        dp[n] = f(m)
    return dp[n]

ans = sum(A)
for i in range(2**N-1, -1, -1):
    if f(i) <= 0:
        continue
    cnt = 0
    for j in range(N):
        if i & (1<<j):
            cnt += A[j]
    ans = min(ans, cnt)

print(ans)
0