結果

問題 No.1375 Divide and Update
ユーザー 沙耶花沙耶花
提出日時 2021-02-05 21:50:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 393 ms / 2,000 ms
コード長 925 bytes
コンパイル時間 2,005 ms
コンパイル使用メモリ 204,976 KB
実行使用メモリ 28,196 KB
最終ジャッジ日時 2023-09-15 08:01:10
合計ジャッジ時間 8,016 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
4,376 KB
testcase_04 AC 1 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 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 332 ms
24,832 KB
testcase_11 AC 299 ms
23,076 KB
testcase_12 AC 164 ms
14,052 KB
testcase_13 AC 139 ms
12,328 KB
testcase_14 AC 375 ms
28,024 KB
testcase_15 AC 372 ms
27,868 KB
testcase_16 AC 378 ms
27,996 KB
testcase_17 AC 374 ms
27,944 KB
testcase_18 AC 385 ms
27,932 KB
testcase_19 AC 393 ms
27,932 KB
testcase_20 AC 335 ms
28,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 10000000000000001

vector<vector<long long>> get(vector<long long> a,long long X){
	vector dp(a.size()+1,vector<long long>(3,-Inf));
	dp[0][0] = 0LL;
	
	rep(i,a.size()){
		rep(j,3){
			long long cost = a[i];
			if(j==1)cost = X;
			dp[i+1][j] = max(dp[i+1][j],dp[i][j] + cost);
			
			if(j==0)cost = X;
			else cost = a[i];
			if(j!=2){
				dp[i+1][j+1] = max(dp[i+1][j+1],dp[i][j] + cost);
			}
			
		}
	}
	
	return dp;
}

int main(){
	int N;
	long long X,Y;
	cin>>N>>X>>Y;
	vector<long long> a(N);
	rep(i,N){
		cin>>a[i];
	}
	
	auto r0 = get(a,X);
	reverse(a.begin(),a.end());
	auto r1 = get(a,Y);
	reverse(a.begin(),a.end());
	
	for(int i=1;i<N-1;i++){
		long long ans = a[i];
		
		ans += max(r0[i][1],r0[i][2]);
		ans += max(r1[N-1-i][1],r1[N-1-i][2]);
		
		cout<<ans<<endl;
		
	}
	
	
	return 0;
}
0