結果

問題 No.90 品物の並び替え
ユーザー nanae
提出日時 2017-01-02 10:32:49
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 820 bytes
コンパイル時間 123 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-12-16 03:06:37
合計ジャッジ時間 1,003 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 5 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

# coding: utf-8
# yukicoder No.90 品物の並び替え

N, M = map(int, input().split())
rule = [[int(i) for i in input().split()] for _ in range(M)]

perm = [0]
total = 0

'''
1 ~ (N - 1) 番の品物を順次どの位置に挿入すれば最大になるか
を調べていく
'''

for i in range(1, N):
    max_add = -1
    
    for j in range(i + 1):
        add = 0
        
        for k in perm[j:]:
            for c in rule:
                if [i, k] == c[:2]:
                    add += c[2]
                    break
        for l in perm[:j]:
            for c in rule:
                if [l, i] == c[:2]:
                    add += c[2]
                    break
        
        if add > max_add:
            max_add = add
            ins = j
    
    perm.insert(ins, i)
    total += max_add

print(total)
0