結果

問題 No.90 品物の並び替え
ユーザー lam6er
提出日時 2025-03-20 20:24:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 358 ms / 5,000 ms
コード長 459 bytes
コンパイル時間 591 ms
コンパイル使用メモリ 82,536 KB
実行使用メモリ 76,148 KB
最終ジャッジ日時 2025-03-20 20:26:15
合計ジャッジ時間 1,579 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

import itertools

n, m = map(int, input().split())
rules = []
for _ in range(m):
    a, b, s = map(int, input().split())
    rules.append((a, b, s))

max_score = 0

for perm in itertools.permutations(range(n)):
    pos = [0] * n
    for idx, item in enumerate(perm):
        pos[item] = idx
    current = 0
    for a, b, s in rules:
        if pos[a] < pos[b]:
            current += s
    if current > max_score:
        max_score = current

print(max_score)
0