結果

問題 No.943 取り調べ
ユーザー 👑 H20H20
提出日時 2022-01-26 12:51:04
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 847 bytes
コンパイル時間 1,365 ms
コンパイル使用メモリ 86,820 KB
実行使用メモリ 82,912 KB
最終ジャッジ日時 2023-08-24 15:47:21
合計ジャッジ時間 5,798 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
71,408 KB
testcase_01 AC 93 ms
71,228 KB
testcase_02 AC 94 ms
71,568 KB
testcase_03 AC 92 ms
71,764 KB
testcase_04 TLE -
testcase_05 -- -
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 #

import collections

N = int(input())
X = []
for _ in range(N):
    X.append(list(map(int,input().split())))

A = list(map(int,input().split()))
ans = 10**20
for i in range(2 ** N):
    cost = 0
    Lie = set()
    for j in range(N):
        if ((i >> j) & 1):
            cost+=A[j]
            Lie.add(j)
    
    M = [[] for _ in range(N)]
    CNT = [0]*N
    #上書きしちゃうが問題なし
    for i in range(N):
        for j in range(N):
            if X[i][j]==1 and (not j in Lie):
                M[j].append(i)
                CNT[i]+=1
    D = collections.deque()
    for i in range(N):
        if CNT[i]==0:
            D.append(i)
    while len(D):
        i = D.pop()
        for j in M[i]:
            CNT[j]-=1
            if CNT[j]==0:
                D.append(j)

    if sum(CNT)==0:
        ans = min(ans,cost)

print(ans)
0