結果

問題 No.90 品物の並び替え
ユーザー 12354865271235486527
提出日時 2019-11-29 01:07:28
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 961 bytes
コンパイル時間 358 ms
コンパイル使用メモリ 10,912 KB
実行使用メモリ 8,696 KB
最終ジャッジ日時 2023-08-12 19:12:53
合計ジャッジ時間 1,621 ms
ジャッジサーバーID
(参考情報)
judge9 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,516 KB
testcase_01 WA -
testcase_02 AC 18 ms
8,644 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 18 ms
8,512 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()
        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