結果

問題 No.90 品物の並び替え
ユーザー 1235486527
提出日時 2019-11-29 01:07:28
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 961 bytes
コンパイル時間 109 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-11-20 09:37:50
合計ジャッジ時間 960 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 2 WA * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

def culc_inc(n, m):
    if m in D[n]:
        return D[n][m]
    else:
        return 0

def insertion():
    sum = 0
    L = [NL.pop()]
    while NL:
        inc = 0
        inc_L = 0
        inc_R = 0
        max_inc = 0
        max_index = 0
        n = NL.pop()
        lng = len(L)
        for i in reversed(range(lng)):
            inc_R = culc_inc(L[i], n) + inc_L
            inc_L += culc_inc(n, L[i])
            inc = max(inc_L, inc_R)
            if inc > max_inc:
                max_inc = inc
                if inc_L < inc_R:
                    max_index = i+1
                else:
                    max_index = i
        L.insert(max_index, n)
        sum += max_inc
    return sum

N, M = map(int,input().split())
NL = [i for i in range(N)]
D = defaultdict(dict)

for i in range(M):
    item1, item2, score = map(int,input().split())
    D2 = {item2: score}
    D[item1].update(D2)

print(insertion())

0