結果

問題 No.1117 数列分割
ユーザー mkawa2mkawa2
提出日時 2023-05-18 17:55:48
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 617 bytes
コンパイル時間 683 ms
コンパイル使用メモリ 87,264 KB
実行使用メモリ 91,600 KB
最終ジャッジ日時 2023-08-22 11:14:15
合計ジャッジ時間 19,196 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
71,752 KB
testcase_01 AC 91 ms
71,708 KB
testcase_02 AC 89 ms
71,760 KB
testcase_03 AC 274 ms
79,240 KB
testcase_04 AC 231 ms
78,188 KB
testcase_05 AC 92 ms
71,420 KB
testcase_06 AC 132 ms
77,876 KB
testcase_07 AC 126 ms
78,112 KB
testcase_08 AC 280 ms
79,284 KB
testcase_09 AC 172 ms
78,296 KB
testcase_10 AC 271 ms
79,120 KB
testcase_11 AC 636 ms
82,208 KB
testcase_12 RE -
testcase_13 AC 666 ms
81,912 KB
testcase_14 AC 866 ms
84,712 KB
testcase_15 RE -
testcase_16 AC 1,165 ms
88,880 KB
testcase_17 AC 287 ms
80,108 KB
testcase_18 AC 148 ms
78,360 KB
testcase_19 RE -
testcase_20 AC 1,034 ms
87,524 KB
testcase_21 AC 1,504 ms
91,116 KB
testcase_22 AC 1,459 ms
91,184 KB
testcase_23 AC 1,480 ms
91,108 KB
testcase_24 AC 1,540 ms
91,540 KB
testcase_25 AC 1,448 ms
91,600 KB
testcase_26 AC 93 ms
71,700 KB
testcase_27 RE -
testcase_28 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

n,k,m=map(int,input().split())
a=list(map(int,input().split()))
s=[0]*(n+1)
for i in range(n):s[i+1]=s[i]+a[i]

def push(q,i,val):
    while q and q[-1][-1]<=val:q.pop()
    q.append((i,val))

dp=[0]+[-1]*n
for _ in range(k):
    q1=deque()
    q2=deque()
    ndp=[-1]*(n+1)
    for i in range(n+1):
        if q1 and q1[0][0]<i-m:q1.popleft()
        if q2 and q2[0][0]<i-m:q2.popleft()
        if q1:ndp[i]=q1[0][1]+s[i]
        if q2:ndp[i]=max(ndp[i],q2[0][1]-s[i])
        if dp[i]!=-1:
            push(q1,i,dp[i]-s[i])
            push(q2,i,dp[i]+s[i])
    dp=ndp

print(dp[-1])
0