結果

問題 No.1117 数列分割
ユーザー mkawa2
提出日時 2020-07-18 18:23:09
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 1,190 bytes
コンパイル時間 178 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 22,656 KB
最終ジャッジ日時 2024-11-30 23:12:33
合計ジャッジ時間 54,270 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16 TLE * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def solve():
    cs = [0]
    for a in aa: cs.append(cs[-1] + a)
    dp = [-inf] * (n + 1)
    dp[0] = 0
    for j in range(k):
        q1 = deque()
        q2 = deque()
        ndp = [-inf] * (n + 1)
        for i in range(n + 1):
            while q1 and q1[0][0] < i - m: q1.popleft()
            while q2 and q2[0][0] < i - m: q2.popleft()
            if q1: ndp[i] = max(q1[0][1] + cs[i], q2[0][1] - cs[i])
            if dp[i] == -inf: continue
            val = dp[i] - cs[i]
            while q1 and q1[-1][1] <= val: q1.pop()
            q1.append((i, val))
            val = dp[i] + cs[i]
            while q2 and q2[-1][1] <= val: q2.pop()
            q2.append((i, val))
            # print(q1,q2)
        dp = ndp
    print(dp[-1])

inf=10**16
n,k,m=MI()
aa=LI()
solve()
0