結果

問題 No.90 品物の並び替え
ユーザー lam6er
提出日時 2025-03-20 18:42:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 376 ms / 5,000 ms
コード長 459 bytes
コンパイル時間 219 ms
コンパイル使用メモリ 82,212 KB
実行使用メモリ 76,004 KB
最終ジャッジ日時 2025-03-20 18:42:35
合計ジャッジ時間 1,582 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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