結果

問題 No.90 品物の並び替え
ユーザー 12354865271235486527
提出日時 2019-11-29 02:43:42
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 945 bytes
コンパイル時間 595 ms
コンパイル使用メモリ 10,892 KB
実行使用メモリ 8,740 KB
最終ジャッジ日時 2023-08-12 23:55:46
合計ジャッジ時間 1,260 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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()
        for i in reversed(range(len(L))):
            inc_R = culc_inc(L[i], n) + inc_L
            inc_L = culc_inc(n, L[i]) + inc_L
            inc = max(inc_L, inc_R)
            if inc > max_inc:
                max_inc = inc
                max_index = (i+1 if inc_L < inc_R else i)
            else:
                max_inc += culc_inc(L[i], n)
        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