結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
86,964 KB
testcase_01 AC 124 ms
86,944 KB
testcase_02 AC 122 ms
86,608 KB
testcase_03 AC 124 ms
86,848 KB
testcase_04 AC 127 ms
88,960 KB
testcase_05 AC 162 ms
91,392 KB
testcase_06 AC 160 ms
91,392 KB
testcase_07 AC 121 ms
86,840 KB
testcase_08 AC 125 ms
89,216 KB
testcase_09 AC 139 ms
90,240 KB
testcase_10 AC 140 ms
89,940 KB
testcase_11 AC 140 ms
89,556 KB
testcase_12 AC 124 ms
86,784 KB
testcase_13 AC 123 ms
86,668 KB
testcase_14 AC 124 ms
87,424 KB
testcase_15 AC 122 ms
86,836 KB
testcase_16 AC 121 ms
86,604 KB
testcase_17 AC 135 ms
89,856 KB
testcase_18 AC 119 ms
86,608 KB
testcase_19 AC 118 ms
86,892 KB
testcase_20 AC 119 ms
86,824 KB
testcase_21 AC 118 ms
86,812 KB
testcase_22 AC 122 ms
87,808 KB
testcase_23 AC 143 ms
91,592 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):
        if dp[s] == 10**10:
            continue
        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