結果
問題 | No.1117 数列分割 |
ユーザー |
![]() |
提出日時 | 2020-07-18 18:23:38 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 715 ms / 3,000 ms |
コード長 | 1,159 bytes |
コンパイル時間 | 391 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 80,512 KB |
最終ジャッジ日時 | 2024-11-30 23:13:20 |
合計ジャッジ時間 | 9,775 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 |
ソースコード
from collections import dequeimport sysint1 = lambda x: int(x) - 1p2D = 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] = 0for 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: continueval = 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 = ndpprint(dp[-1])inf=10**16n,k,m=MI()aa=LI()solve()