結果

問題 No.1117 数列分割
ユーザー 👑 NachiaNachia
提出日時 2021-01-04 15:42:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,686 ms / 3,000 ms
コード長 947 bytes
コンパイル時間 2,593 ms
コンパイル使用メモリ 214,040 KB
実行使用メモリ 151,428 KB
最終ジャッジ日時 2023-08-05 03:32:27
合計ジャッジ時間 19,338 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
9,620 KB
testcase_01 AC 5 ms
9,456 KB
testcase_02 AC 6 ms
9,468 KB
testcase_03 AC 72 ms
43,532 KB
testcase_04 AC 68 ms
39,540 KB
testcase_05 AC 5 ms
9,440 KB
testcase_06 AC 7 ms
13,972 KB
testcase_07 AC 6 ms
11,792 KB
testcase_08 AC 51 ms
31,296 KB
testcase_09 AC 18 ms
18,520 KB
testcase_10 AC 50 ms
27,248 KB
testcase_11 AC 269 ms
61,184 KB
testcase_12 AC 301 ms
69,480 KB
testcase_13 AC 599 ms
97,216 KB
testcase_14 AC 549 ms
82,244 KB
testcase_15 AC 809 ms
109,128 KB
testcase_16 AC 836 ms
92,688 KB
testcase_17 AC 35 ms
19,416 KB
testcase_18 AC 1,284 ms
151,240 KB
testcase_19 AC 1,513 ms
151,228 KB
testcase_20 AC 622 ms
80,312 KB
testcase_21 AC 1,655 ms
151,428 KB
testcase_22 AC 1,686 ms
150,520 KB
testcase_23 AC 1,582 ms
150,148 KB
testcase_24 AC 1,609 ms
149,196 KB
testcase_25 AC 1,589 ms
149,280 KB
testcase_26 AC 6 ms
9,484 KB
testcase_27 AC 25 ms
15,296 KB
testcase_28 AC 22 ms
15,244 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using LL=long long;
using ULL=unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

const LL INF=1000000000000000;

int N,K,M;
LL A[2][3001];
LL dp[2][3001][3001];
deque<int> dpw[2][3001];

int main(){
	cin>>N>>K>>M;
	rep(i,N) cin>>A[0][i]; A[0][N]=0;
	for(int i=N-1; i>=0; i--) A[0][i]+=A[0][i+1];
	rep(i,N+1) A[1][i]=-A[0][i];

	rep(t,2) rep(i,N+1) rep(k,K+1) dp[t][k][i]=-INF;
	rep(t,2) dp[t][0][0]=A[t][0];
	rep(t,2) rep(k,K+1) dpw[t][k]={0};

	rep(i,N) rep(k,K){
		LL tmp = -INF;
		rep(t,2){
			if(dpw[t][k].size()) if(dpw[t][k].front()<=i-M) dpw[t][k].pop_front();
			if(dpw[t][k].size()) tmp=max(tmp,dp[t][k][dpw[t][k].front()]-A[t][i+1]);
		}
		rep(t,2){
			dp[t][k+1][i+1]=tmp+A[t][i+1];
			while(dpw[t][k+1].size()) if(dp[t][k+1][dpw[t][k+1].back()]<=dp[t][k+1][i+1]) dpw[t][k+1].pop_back(); else break;
			dpw[t][k+1].push_back(i+1);
		}
	}

	cout<<dp[0][K][N]<<endl;

	return 0;
}
0