結果

問題 No.357 品物の並び替え (Middle)
ユーザー tcltktcltk
提出日時 2021-05-18 04:20:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 275 ms / 5,000 ms
コード長 869 bytes
コンパイル時間 280 ms
コンパイル使用メモリ 82,224 KB
実行使用メモリ 90,408 KB
最終ジャッジ日時 2024-04-16 18:42:21
合計ジャッジ時間 4,397 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 157 ms
89,172 KB
testcase_01 AC 129 ms
86,920 KB
testcase_02 AC 142 ms
89,264 KB
testcase_03 AC 141 ms
88,760 KB
testcase_04 AC 153 ms
89,264 KB
testcase_05 AC 154 ms
88,840 KB
testcase_06 AC 130 ms
87,160 KB
testcase_07 AC 126 ms
86,540 KB
testcase_08 AC 176 ms
89,548 KB
testcase_09 AC 234 ms
90,136 KB
testcase_10 AC 187 ms
90,016 KB
testcase_11 AC 184 ms
89,868 KB
testcase_12 AC 275 ms
90,408 KB
testcase_13 AC 232 ms
90,156 KB
testcase_14 AC 232 ms
90,196 KB
testcase_15 AC 182 ms
89,820 KB
testcase_16 AC 193 ms
90,044 KB
testcase_17 AC 184 ms
89,932 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, M = map(int, input().split())
    score = [[0] * N for _ in range(N)]
    for _ in range(M):
        i, j, n = map(int, input().split())
        score[i-1][j-1] = n

    dp = [0] * (1<<N)
    for s in range(1<<N):
        for i in range(N):
            if s & (1<<i):
                continue
            score1 = sum(score[j][i] for j in range(N) if s & (1<<j))
            dp[s | (1<<i)] = max(dp[s | (1<<i)], dp[s] + score1)
    ans = dp[(1<<N)-1]
    print(ans)


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