結果

問題 No.1375 Divide and Update
ユーザー outlineoutline
提出日時 2021-02-05 22:27:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 75 ms / 2,000 ms
コード長 1,895 bytes
コンパイル時間 3,489 ms
コンパイル使用メモリ 139,744 KB
実行使用メモリ 25,980 KB
最終ジャッジ日時 2023-09-15 08:53:34
合計ジャッジ時間 4,455 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 64 ms
22,912 KB
testcase_11 AC 59 ms
21,136 KB
testcase_12 AC 33 ms
13,064 KB
testcase_13 AC 28 ms
11,152 KB
testcase_14 AC 72 ms
25,980 KB
testcase_15 AC 73 ms
25,668 KB
testcase_16 AC 72 ms
25,544 KB
testcase_17 AC 72 ms
25,732 KB
testcase_18 AC 75 ms
25,752 KB
testcase_19 AC 74 ms
25,556 KB
testcase_20 AC 61 ms
25,620 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
using namespace std;

using ll = long long;
constexpr int INF = 1001001001;
// constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N, X, Y;
    cin >> N >> X >> Y;
    vector<int> a(N);
    for(int i = 0; i < N; ++i)  cin >> a[i];

    constexpr ll inf = 1e+17;
    vector<vector<ll>> prefix(N + 1, vector<ll>(3, -inf));
    auto suffix = prefix;
    prefix[0][0] = 0;
    for(int i = 0; i < N; ++i){
        chmax(prefix[i + 1][0], prefix[i][0] + a[i]);
        chmax(prefix[i + 1][1], max(prefix[i][0], prefix[i][1]) + X);
        chmax(prefix[i + 1][2], max(max(prefix[i][0], prefix[i][1]) + X, prefix[i][2] + a[i]));
    }
    suffix[N][0] = 0;
    for(int i = N - 1; i >= 0; --i){
        chmax(suffix[i][0], suffix[i + 1][0] + a[i]);
        chmax(suffix[i][1], max(suffix[i + 1][0], suffix[i + 1][1]) + Y);
        chmax(suffix[i][2], max(max(suffix[i + 1][0], suffix[i + 1][1]) + Y, suffix[i + 1][2] + a[i]));
    }

    for(int i = 1; i < N - 1; ++i){
        cout << prefix[i][2] + a[i] + suffix[i + 1][2] << '\n';
    }

    return 0;
}
0