結果

問題 No.1117 数列分割
ユーザー okok
提出日時 2020-07-18 10:07:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 103 ms / 3,000 ms
コード長 1,256 bytes
コンパイル時間 911 ms
コンパイル使用メモリ 84,472 KB
実行使用メモリ 73,600 KB
最終ジャッジ日時 2024-05-07 23:32:11
合計ジャッジ時間 2,670 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 12 ms
26,452 KB
testcase_04 AC 9 ms
26,448 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 3 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 14 ms
34,392 KB
testcase_09 AC 6 ms
22,096 KB
testcase_10 AC 15 ms
36,864 KB
testcase_11 AC 42 ms
54,996 KB
testcase_12 AC 39 ms
52,844 KB
testcase_13 AC 37 ms
48,968 KB
testcase_14 AC 64 ms
63,156 KB
testcase_15 AC 49 ms
55,072 KB
testcase_16 AC 76 ms
72,200 KB
testcase_17 AC 27 ms
73,408 KB
testcase_18 AC 93 ms
72,840 KB
testcase_19 AC 94 ms
72,688 KB
testcase_20 AC 73 ms
72,608 KB
testcase_21 AC 90 ms
73,016 KB
testcase_22 AC 88 ms
72,924 KB
testcase_23 AC 89 ms
73,600 KB
testcase_24 AC 92 ms
72,468 KB
testcase_25 AC 103 ms
72,900 KB
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 20 ms
71,656 KB
testcase_28 AC 19 ms
71,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;


signed main(){
	cout<<fixed<<setprecision(10);
	
	constexpr int MAX = 3010;
	int N, K, M, A;
	
	static int dp[MAX][MAX];
	int sum[MAX];
	pair<int,int> q[MAX], q2[MAX];
	
	cin>>N>>K>>M;
	
	sum[0] = 0;
	
	for(int i = 0; i < N; i++){
		cin>>A;
	
		sum[i+1] = sum[i] + A;
		
		if(i < M) dp[i][1] = abs(sum[i+1]);
	}

	for(int j = 2; j <= K; j++){
		int f = 0, e = 0, f2 = 0, e2 = 0;
		
		for(int i = j-1; i < N; i++){
			int num = dp[i-1][j-1] - sum[i];
			int num2 = dp[i-1][j-1] + sum[i];
			
			while(e - f && q[e-1].second < num) e--;
			q[e] = {i,num}; e++;
			while(e - f && q[f].first < i - M + 1) f++;
			
			while(e2 - f2 && q2[e2-1].second < num2) e2--;
			q2[e2] = {i,num2}; e2++;
			while(e2 - f2  && q2[f2].first < i - M + 1) f2++;
			
			dp[i][j] = max(q[f].second + sum[i+1], q2[f2].second - sum[i+1]);
		}
	}
	
	cout<<dp[N-1][K]<<endl;
	
	return 0;
}
0