結果

問題 No.943 取り調べ
ユーザー OKCH3COOHOKCH3COOH
提出日時 2019-12-08 19:06:53
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
TLE  
実行時間 -
コード長 761 bytes
コンパイル時間 94 ms
コンパイル使用メモリ 10,980 KB
実行使用メモリ 12,764 KB
最終ジャッジ日時 2023-08-30 02:34:50
合計ジャッジ時間 4,535 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
12,256 KB
testcase_01 AC 17 ms
8,004 KB
testcase_02 AC 18 ms
7,892 KB
testcase_03 AC 16 ms
7,880 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())
INF = 10**10

parent = []
for _ in range(N):
    state = 0
    for i, s in enumerate(input().split()):
        if s == '1':
            state |= (1 << i)
    parent.append(state)
A = tuple(map(int, input().split()))

ans = INF
for mask in range(1 << N):
    state = mask
    V = set(range(N))

    while True:
        W = set()
        for v in V:
            if (parent[v] & state) == parent[v]:
                state |= (1 << v)
            else:
                W.add(v)
        if W == V:
            break
        V = W
        if len(V) == 0:
            cost = 0
            for i, a in enumerate(A):
                if (mask & (1 << i)) != 0:
                    cost += a
            ans = min(ans, cost)
            break

print(ans)
0