結果

問題 No.1117 数列分割
ユーザー okok
提出日時 2020-07-18 19:17:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 39 ms / 3,000 ms
コード長 1,155 bytes
コンパイル時間 470 ms
コンパイル使用メモリ 66,288 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-20 20:28:11
合計ジャッジ時間 1,734 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 5 ms
4,376 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 5 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 6 ms
4,380 KB
testcase_11 AC 17 ms
4,380 KB
testcase_12 AC 16 ms
4,376 KB
testcase_13 AC 15 ms
4,376 KB
testcase_14 AC 23 ms
4,380 KB
testcase_15 AC 20 ms
4,376 KB
testcase_16 AC 34 ms
4,376 KB
testcase_17 AC 8 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 34 ms
4,376 KB
testcase_20 AC 31 ms
4,380 KB
testcase_21 AC 38 ms
4,380 KB
testcase_22 AC 38 ms
4,376 KB
testcase_23 AC 39 ms
4,376 KB
testcase_24 AC 38 ms
4,380 KB
testcase_25 AC 38 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 3 ms
4,380 KB
testcase_28 AC 3 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>

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;

constexpr int MAX = 3100;
	
int dp[MAX][2];
int sum[MAX];
static int qf[MAX], q2f[MAX];
static int qs[MAX], q2s[MAX];

signed main(){
	int N, K, M, A;
	

	
	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, k = 0; j <= K; j++, k = !k){
		int f = 0, e = 0, f2 = 0, e2 = 0;
		int L = min(N, M * j);
		
		for(int i = j-1; i < L; i++){
			int num = dp[i-1][!k] - sum[i];
			int num2 = dp[i-1][!k] + sum[i];
			
			while(e - f && qs[e-1] < num) e--;
			qf[e] = i;
			qs[e] = num;
			e++;
			while(e - f && qf[f] < i - M + 1) f++;
			
			while(e2 - f2 && q2s[e2-1] < num2) e2--;
			q2f[e2] = i;
			q2s[e2] = num2;
			e2++;
			while(e2 - f2 && q2f[f2] < i - M + 1) f2++;
			
			dp[i][k] = max(qs[f] + sum[i+1], q2s[f2]  - sum[i+1]);
		}
	}
	
	cout<<dp[N-1][K%2]<<endl;
	
	return 0;
}
0