結果

問題 No.1117 数列分割
ユーザー tktk_snsntktk_snsn
提出日時 2021-05-15 14:25:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,837 ms / 3,000 ms
コード長 801 bytes
コンパイル時間 318 ms
コンパイル使用メモリ 82,360 KB
実行使用メモリ 140,444 KB
最終ジャッジ日時 2024-04-14 05:00:32
合計ジャッジ時間 30,954 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
54,992 KB
testcase_01 AC 49 ms
55,528 KB
testcase_02 AC 49 ms
54,200 KB
testcase_03 AC 377 ms
79,140 KB
testcase_04 AC 302 ms
79,036 KB
testcase_05 AC 43 ms
54,176 KB
testcase_06 AC 99 ms
76,620 KB
testcase_07 AC 102 ms
76,796 KB
testcase_08 AC 311 ms
79,400 KB
testcase_09 AC 154 ms
76,584 KB
testcase_10 AC 309 ms
79,504 KB
testcase_11 AC 803 ms
86,056 KB
testcase_12 AC 841 ms
86,188 KB
testcase_13 AC 1,099 ms
88,212 KB
testcase_14 AC 1,205 ms
92,448 KB
testcase_15 AC 1,464 ms
94,940 KB
testcase_16 AC 1,611 ms
100,616 KB
testcase_17 AC 341 ms
80,716 KB
testcase_18 AC 2,709 ms
140,444 KB
testcase_19 AC 2,837 ms
127,200 KB
testcase_20 AC 1,374 ms
99,096 KB
testcase_21 AC 2,499 ms
115,028 KB
testcase_22 AC 2,483 ms
116,680 KB
testcase_23 AC 2,581 ms
119,372 KB
testcase_24 AC 2,484 ms
118,204 KB
testcase_25 AC 2,478 ms
116,416 KB
testcase_26 AC 43 ms
54,000 KB
testcase_27 AC 327 ms
80,812 KB
testcase_28 AC 296 ms
80,044 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
from itertools import accumulate
inf = 10**15


def sliding_max(A, rng):
    d = deque()
    for i, a in enumerate(A):
        while d and d[0] <= i - rng:
            d.popleft()
        while d and A[d[-1]] < a:
            d.pop()
        d.append(i)
        yield A[d[0]]


N, K, M = map(int, input().split())
A = list(map(int, input().split()))
S = [0] + list(accumulate(A))

dp = [-inf] * (N+1)
dp[0] = 0

for i in range(K):
    newDP = [-1] * (N+1)

    val = tuple(dp[j] - S[j] for j in range(N))
    for j, x in enumerate(sliding_max(val, M), 1):
        newDP[j] = max(newDP[j], x + S[j])

    val = tuple(dp[j] + S[j] for j in range(N))
    for j, x in enumerate(sliding_max(val, M), 1):
        newDP[j] = max(newDP[j], x - S[j])

    dp = newDP

print(dp[N])
0