結果

問題 No.90 品物の並び替え
ユーザー nanaenanae
提出日時 2017-01-02 10:32:49
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 820 bytes
コンパイル時間 360 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-05-09 13:27:21
合計ジャッジ時間 1,089 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,752 KB
testcase_01 WA -
testcase_02 AC 28 ms
10,752 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 30 ms
10,752 KB
testcase_07 AC 28 ms
10,752 KB
testcase_08 AC 28 ms
10,752 KB
testcase_09 AC 33 ms
10,624 KB
権限があれば一括ダウンロードができます

ソースコード

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