結果

問題 No.1117 数列分割
ユーザー 👑 NachiaNachia
提出日時 2021-01-04 15:42:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,828 ms / 3,000 ms
コード長 947 bytes
コンパイル時間 2,719 ms
コンパイル使用メモリ 210,664 KB
実行使用メモリ 151,596 KB
最終ジャッジ日時 2024-04-23 02:01:45
合計ジャッジ時間 20,190 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
9,628 KB
testcase_01 AC 5 ms
9,756 KB
testcase_02 AC 4 ms
9,768 KB
testcase_03 AC 71 ms
42,948 KB
testcase_04 AC 69 ms
38,880 KB
testcase_05 AC 5 ms
9,752 KB
testcase_06 AC 7 ms
14,060 KB
testcase_07 AC 7 ms
14,036 KB
testcase_08 AC 47 ms
30,168 KB
testcase_09 AC 17 ms
18,536 KB
testcase_10 AC 45 ms
29,200 KB
testcase_11 AC 288 ms
60,164 KB
testcase_12 AC 329 ms
69,124 KB
testcase_13 AC 622 ms
95,936 KB
testcase_14 AC 619 ms
80,968 KB
testcase_15 AC 893 ms
107,988 KB
testcase_16 AC 898 ms
91,756 KB
testcase_17 AC 33 ms
18,308 KB
testcase_18 AC 1,444 ms
151,596 KB
testcase_19 AC 1,685 ms
151,468 KB
testcase_20 AC 708 ms
81,600 KB
testcase_21 AC 1,804 ms
151,456 KB
testcase_22 AC 1,753 ms
150,576 KB
testcase_23 AC 1,732 ms
150,388 KB
testcase_24 AC 1,746 ms
150,052 KB
testcase_25 AC 1,828 ms
148,620 KB
testcase_26 AC 5 ms
9,768 KB
testcase_27 AC 23 ms
15,728 KB
testcase_28 AC 21 ms
15,192 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