結果

問題 No.943 取り調べ
ユーザー tcltktcltk
提出日時 2021-05-19 16:27:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 688 ms / 1,206 ms
コード長 997 bytes
コンパイル時間 438 ms
コンパイル使用メモリ 82,204 KB
実行使用メモリ 91,520 KB
最終ジャッジ日時 2024-04-18 02:34:14
合計ジャッジ時間 6,283 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
86,652 KB
testcase_01 AC 124 ms
86,656 KB
testcase_02 AC 121 ms
86,784 KB
testcase_03 AC 121 ms
86,912 KB
testcase_04 AC 688 ms
91,392 KB
testcase_05 AC 239 ms
91,456 KB
testcase_06 AC 236 ms
91,520 KB
testcase_07 AC 118 ms
86,656 KB
testcase_08 AC 680 ms
91,392 KB
testcase_09 AC 186 ms
89,984 KB
testcase_10 AC 191 ms
89,848 KB
testcase_11 AC 163 ms
89,856 KB
testcase_12 AC 123 ms
87,024 KB
testcase_13 AC 136 ms
89,344 KB
testcase_14 AC 144 ms
89,472 KB
testcase_15 AC 122 ms
87,040 KB
testcase_16 AC 117 ms
86,852 KB
testcase_17 AC 206 ms
89,984 KB
testcase_18 AC 122 ms
87,012 KB
testcase_19 AC 135 ms
89,576 KB
testcase_20 AC 126 ms
87,040 KB
testcase_21 AC 121 ms
86,836 KB
testcase_22 AC 222 ms
89,728 KB
testcase_23 AC 278 ms
91,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#region Header
#!/usr/bin/env python3
# from typing import *

import sys
import io
import math
import collections
import decimal
import itertools
import bisect
import heapq


def input():
    return sys.stdin.readline()[:-1]


# sys.setrecursionlimit(1000000)
#endregion

# _INPUT = """# paste here...
# """
# sys.stdin = io.StringIO(_INPUT)


def main():
    N = int(input())
    X = [list(map(int, input().split())) for _ in range(N)]
    Dependant = [[j for j in range(N) if X[i][j] == 1] for i in range(N)]
    A = list(map(int, input().split()))

    dp = [10**10] * (1<<N)
    dp[0] = 0
    for s in range(1<<N):
        for i in range(N):
            if s & (1<<i):
                continue
            v = dp[s]
            s1 = s | (1<<i)
            for j in Dependant[i]:
                if not(s & (1<<j)):
                    v += A[j]
                    s1 |= (1<<j)
            dp[s1] = min(dp[s1], v)

    ans = dp[(1<<N)-1]
    print(ans)


if __name__ == '__main__':
    main()
0