結果

問題 No.1117 数列分割
ユーザー okok
提出日時 2020-07-18 09:16:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,360 bytes
コンパイル時間 1,403 ms
コンパイル使用メモリ 100,184 KB
実行使用メモリ 73,856 KB
最終ジャッジ日時 2024-05-07 23:25:44
合計ジャッジ時間 5,058 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 18 ms
8,704 KB
testcase_04 AC 13 ms
8,320 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 18 ms
7,552 KB
testcase_09 AC 6 ms
5,376 KB
testcase_10 AC 20 ms
7,808 KB
testcase_11 AC 91 ms
21,888 KB
testcase_12 AC 83 ms
22,784 KB
testcase_13 AC 84 ms
30,848 KB
testcase_14 AC 136 ms
32,128 KB
testcase_15 AC 130 ms
39,040 KB
testcase_16 AC 196 ms
43,648 KB
testcase_17 AC 21 ms
7,552 KB
testcase_18 AC 270 ms
73,856 KB
testcase_19 AC 261 ms
73,856 KB
testcase_20 AC 181 ms
37,504 KB
testcase_21 AC 257 ms
73,856 KB
testcase_22 AC 248 ms
72,832 KB
testcase_23 AC 252 ms
72,704 KB
testcase_24 AC 250 ms
71,936 KB
testcase_25 AC 248 ms
71,552 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 WA -
testcase_28 WA -
権限があれば一括ダウンロードができます

ソースコード

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);
	
	int N, K, M;
	vector<int> A;
	vector<int> sum;
	vector<vector<int>> dp;
	vector<deque<int>> q, q2;
	cin>>N>>K>>M;
	
	A.resize(N);
	dp.resize(N+1, vector<int>(K+1, -INF));
	sum.resize(N+1);
	
	for(int i = 0; i < N; i++){
		cin>>A[i];
	
		sum[i+1] = sum[i] + A[i];
		
		if(i < M) dp[i][1] = abs(sum[i+1]);
	}

	for(int j = 2; j <= K; j++){
		deque<pair<int,int>> q, q2;
		
		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(q.size() && q.back().second < num) q.pop_back();
			q.emplace_back(i, num);
			while(q.size() && q.front().first < i - M) q.pop_front();
			
			while(q2.size() && q2.back().second < num2) q2.pop_back();
			q2.emplace_back(i, num2);
			while(q2.size() && q2.front().first < i - M) q2.pop_front();
			
			dp[i][j] = max(q.front().second + sum[i+1], q2.front().second - sum[i+1]);
		}
	}

	
	cout<<dp[N-1][K]<<endl;
	
	return 0;
}
0