結果

問題 No.90 品物の並び替え
ユーザー tnodino
提出日時 2022-03-01 05:32:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 865 ms / 5,000 ms
コード長 469 bytes
コンパイル時間 335 ms
コンパイル使用メモリ 82,020 KB
実行使用メモリ 130,544 KB
最終ジャッジ日時 2024-07-07 08:05:09
合計ジャッジ時間 2,569 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import permutations
N,M = map(int,input().split())
L = [list(map(int,input().split())) for _ in range(M)]
item1,item2,score = [list(i) for i in zip(*L)]
L = [i for i in range(N)]
L = list(permutations(L, N))
ans = 0
for i in range(len(L)):
    P = L[i]
    memo = {}
    for k in range(N):
        memo[P[k]] = k
    cnt = 0
    for k in range(M):
        if memo[item1[k]] < memo[item2[k]]:
            cnt += score[k]
    ans = max(ans, cnt)
print(ans)
0