結果

問題 No.1375 Divide and Update
ユーザー tkmst201tkmst201
提出日時 2021-02-06 10:06:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 1,311 bytes
コンパイル時間 1,872 ms
コンパイル使用メモリ 203,996 KB
実行使用メモリ 25,880 KB
最終ジャッジ日時 2023-09-15 14:33:33
合計ジャッジ時間 5,226 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 73 ms
23,036 KB
testcase_11 AC 67 ms
21,220 KB
testcase_12 AC 37 ms
13,180 KB
testcase_13 AC 31 ms
11,408 KB
testcase_14 AC 83 ms
25,792 KB
testcase_15 AC 83 ms
25,788 KB
testcase_16 AC 82 ms
25,880 KB
testcase_17 AC 81 ms
25,860 KB
testcase_18 AC 84 ms
25,732 KB
testcase_19 AC 81 ms
25,860 KB
testcase_20 AC 69 ms
25,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = false;
//---------------------------------//

int main() {
	int N, X, Y;
	cin >> N >> X >> Y;
	vector<int> A(N);
	REP(i, N) scanf("%d", &A[i]);
	
	auto func = [&](int X, bool isrev) {
		if (isrev) reverse(ALL(A));
		vector dp(N, vector(3, -longINF)); // [i][j] := j=1: 区間継続, j=2: 区間終了後
		dp[0][0] = 0;
		REP(i, N) {
			chmax(dp[i][2], dp[i][1]);
			if (i + 1 < N) {
				REP(j, 3) {
					if (dp[i][j] == -longINF) continue;
					chmax(dp[i + 1][j], dp[i][j] + (j == 1 ? X : A[i]));
					if (j == 0) chmax(dp[i + 1][1], dp[i][0] + X);
				}
			}
		}
		
		if (isrev) reverse(ALL(A));
		return dp;
	};
	
	auto dp1 = func(X, false);
	auto dp2 = func(Y, true);
	
	FOR(i, 1, N - 1) printf("%lld\n", dp1[i][2] + dp2[N - i - 1][2] + A[i]);
}
0