結果

問題 No.1117 数列分割
ユーザー tktk_snsntktk_snsn
提出日時 2021-05-15 13:44:02
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 863 bytes
コンパイル時間 252 ms
コンパイル使用メモリ 82,352 KB
実行使用メモリ 190,712 KB
最終ジャッジ日時 2024-04-14 04:22:03
合計ジャッジ時間 32,693 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
55,312 KB
testcase_01 AC 40 ms
55,868 KB
testcase_02 AC 40 ms
55,320 KB
testcase_03 AC 361 ms
83,964 KB
testcase_04 AC 301 ms
83,860 KB
testcase_05 AC 41 ms
55,724 KB
testcase_06 AC 93 ms
77,232 KB
testcase_07 AC 90 ms
76,656 KB
testcase_08 AC 338 ms
84,036 KB
testcase_09 AC 186 ms
79,248 KB
testcase_10 AC 314 ms
83,696 KB
testcase_11 AC 857 ms
102,204 KB
testcase_12 AC 904 ms
103,908 KB
testcase_13 AC 1,195 ms
113,420 KB
testcase_14 AC 1,262 ms
117,664 KB
testcase_15 AC 1,543 ms
125,884 KB
testcase_16 AC 1,687 ms
135,936 KB
testcase_17 AC 314 ms
83,700 KB
testcase_18 AC 2,944 ms
190,712 KB
testcase_19 TLE -
testcase_20 AC 1,405 ms
125,248 KB
testcase_21 AC 2,634 ms
174,912 KB
testcase_22 AC 2,630 ms
172,348 KB
testcase_23 AC 2,790 ms
177,224 KB
testcase_24 AC 2,668 ms
174,020 KB
testcase_25 AC 2,627 ms
173,436 KB
testcase_26 AC 41 ms
54,392 KB
testcase_27 AC 324 ms
82,456 KB
testcase_28 AC 300 ms
82,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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


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[j,i]: i桁目までみた、j個かたまりできた-> max
dp = [[-inf]*(N+1) for _ in range(K+1)]
dp[0][0] = 0
for i in range(K):
    val = tuple(dp[i][j] - S[j] for j in range(N))
    for j, x in enumerate(sliding_max(val, M), 1):
        dp[i+1][j] = max(dp[i+1][j], x + S[j])

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

print(dp[K][N])
0