結果

問題 No.943 取り調べ
ユーザー tcltktcltk
提出日時 2021-05-19 16:37:27
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,479 bytes
コンパイル時間 719 ms
コンパイル使用メモリ 82,584 KB
実行使用メモリ 523,136 KB
最終ジャッジ日時 2024-04-18 02:44:16
合計ジャッジ時間 4,122 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
93,528 KB
testcase_01 AC 118 ms
86,788 KB
testcase_02 AC 113 ms
86,852 KB
testcase_03 AC 120 ms
86,944 KB
testcase_04 AC 119 ms
89,000 KB
testcase_05 MLE -
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

    q = collections.deque()
    q.append(0)
    while q:
        s = q.pop()
        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)
            q.appendleft(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