結果

問題 No.90 品物の並び替え
コンテスト
ユーザー lam6er
提出日時 2025-03-20 18:42:23
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 309 ms / 5,000 ms
コード長 459 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 240 ms
コンパイル使用メモリ 96,112 KB
実行使用メモリ 83,840 KB
最終ジャッジ日時 2026-07-07 07:22:29
合計ジャッジ時間 2,476 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 9
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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