結果

問題 No.1117 数列分割
ユーザー tktk_snsntktk_snsn
提出日時 2021-03-15 22:21:14
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 792 bytes
コンパイル時間 252 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 342,232 KB
最終ジャッジ日時 2024-04-25 01:30:28
合計ジャッジ時間 10,182 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
58,368 KB
testcase_01 AC 42 ms
52,480 KB
testcase_02 AC 43 ms
52,736 KB
testcase_03 AC 1,090 ms
203,520 KB
testcase_04 AC 830 ms
157,704 KB
testcase_05 AC 43 ms
52,608 KB
testcase_06 AC 103 ms
76,928 KB
testcase_07 AC 110 ms
77,244 KB
testcase_08 AC 768 ms
169,432 KB
testcase_09 AC 331 ms
99,712 KB
testcase_10 AC 772 ms
171,776 KB
testcase_11 MLE -
testcase_12 MLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
from itertools import accumulate

N, K, M = map(int, input().split())
A = list(map(int, input().split()))
B = list(accumulate(A))

X = [[] for _ in range(K+1)]
Y = [[] for _ in range(K+1)]
for i in range(K):
    X[i].append((0, N+1))
    Y[i].append((0, N+1))

dp = [[0] * (K + 1) for _ in range(N + 1)]
for i, b in enumerate(B, 1):
    L = max(0, i - M)
    for j in reversed(range(1, K + 1)):
        while X[j-1] and X[j-1][0][1] < L:
            heapq.heappop(X[j-1])
        while Y[j-1] and Y[j-1][0][1] < L:
            heapq.heappop(Y[j-1])
        val = 0
        val = max(val, b - X[j-1][0][0])
        val = max(val, -Y[j-1][0][0] - b)
        dp[i][j] = val
        heapq.heappush(X[j], (-(val - b), i))
        heapq.heappush(Y[j], (-(val + b), i))

print(dp[N][K])
0