結果

問題 No.1117 数列分割
ユーザー 👑 NachiaNachia
提出日時 2021-01-04 15:46:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,559 ms / 3,000 ms
コード長 947 bytes
コンパイル時間 2,676 ms
コンパイル使用メモリ 210,408 KB
実行使用メモリ 151,544 KB
最終ジャッジ日時 2024-04-23 02:05:00
合計ジャッジ時間 18,522 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
7,552 KB
testcase_01 AC 5 ms
7,552 KB
testcase_02 AC 5 ms
7,680 KB
testcase_03 AC 68 ms
21,760 KB
testcase_04 AC 67 ms
19,968 KB
testcase_05 AC 5 ms
7,680 KB
testcase_06 AC 7 ms
8,320 KB
testcase_07 AC 5 ms
7,936 KB
testcase_08 AC 50 ms
18,176 KB
testcase_09 AC 17 ms
10,880 KB
testcase_10 AC 45 ms
18,048 KB
testcase_11 AC 253 ms
49,280 KB
testcase_12 AC 286 ms
52,864 KB
testcase_13 AC 548 ms
71,168 KB
testcase_14 AC 530 ms
72,576 KB
testcase_15 AC 777 ms
88,832 KB
testcase_16 AC 785 ms
90,240 KB
testcase_17 AC 31 ms
16,128 KB
testcase_18 AC 1,318 ms
151,544 KB
testcase_19 AC 1,510 ms
151,396 KB
testcase_20 AC 581 ms
76,928 KB
testcase_21 AC 1,511 ms
151,296 KB
testcase_22 AC 1,559 ms
149,376 KB
testcase_23 AC 1,482 ms
149,376 KB
testcase_24 AC 1,482 ms
147,328 KB
testcase_25 AC 1,521 ms
147,200 KB
testcase_26 AC 5 ms
7,808 KB
testcase_27 AC 23 ms
12,524 KB
testcase_28 AC 21 ms
12,544 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[3001][2];
LL dp[3001][3001][2];
deque<int> dpw[3001][2];

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

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

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

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

	return 0;
}
0