結果

問題 No.1375 Divide and Update
ユーザー RheoTommyRheoTommy
提出日時 2021-02-05 23:25:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,398 bytes
コンパイル時間 2,033 ms
コンパイル使用メモリ 201,220 KB
実行使用メモリ 14,236 KB
最終ジャッジ日時 2023-09-15 10:53:51
合計ジャッジ時間 7,405 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 2 ms
4,380 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 155 ms
7,828 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 308 ms
14,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (int) n; i++)

using ll = long long;
using namespace std;

const long long INF = 1ll << 60;

void chmax(ll &x, ll y) {
    x = max(x, y);
}

void chmin(ll &x, ll y) {
    x = min(x, y);
}

ll dp[300000][3];

ll dp2[300000][3];

int main() {
    ll n, x, y;
    cin >> n >> x >> y;
    
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    
    rep(i, n) {
        chmax(dp[i + 1][0], dp[i][0] + a[i]);
        chmax(dp[i + 1][2], dp[i][2] + a[i]);
        chmax(dp[i + 1][1], dp[i][0] + x);
        chmax(dp[i + 1][2], dp[i][0] + x);
        chmax(dp[i + 1][1], dp[i][1] + x);
        chmax(dp[i + 1][2], dp[i][1] + x);
    }
    
//    rep(i, n + 1) {
//        cout << dp[i][0] << " " << dp[i][1] << " " << dp[i][2] << endl;
//    }
    
    reverse(a.begin(), a.end());
    
    rep(i, n) {
        chmax(dp2[i + 1][0], dp2[i][0] + a[i]);
        chmax(dp2[i + 1][2], dp2[i][2] + a[i]);
        chmax(dp2[i + 1][1], dp2[i][0] + y);
        chmax(dp2[i + 1][2], dp2[i][0] + y);
        chmax(dp2[i + 1][1], dp2[i][1] + y);
        chmax(dp2[i + 1][2], dp2[i][1] + y);
    }
    
//    rep(i, n + 1) {
//        cout << dp2[i][0] << " " << dp2[i][1] << " " << dp2[i][2] << endl;
//    }
    
    reverse(a.begin(), a.end());
    
    for (ll i = 1; i < n - 1; i++) {
        cout << dp[i][2] + a[i] + dp2[n - i - 1][2] << endl;
    }
}
0