結果

問題 No.943 取り調べ
ユーザー tcltktcltk
提出日時 2021-05-19 16:38:34
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,474 bytes
コンパイル時間 140 ms
コンパイル使用メモリ 82,604 KB
実行使用メモリ 444,952 KB
最終ジャッジ日時 2024-04-18 02:45:22
合計ジャッジ時間 3,479 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
93,756 KB
testcase_01 AC 128 ms
86,740 KB
testcase_02 AC 118 ms
87,008 KB
testcase_03 AC 114 ms
86,412 KB
testcase_04 AC 125 ms
88,764 KB
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 #

#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

    k = 0
    L = [0]
    while k < len(L):
        s = L[k]
        k += 1
        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)
            L.append(s1)

    # 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