結果

問題 No.1375 Divide and Update
ユーザー sten_sansten_san
提出日時 2021-02-06 01:18:20
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 376 ms / 2,000 ms
コード長 1,953 bytes
コンパイル時間 2,023 ms
コンパイル使用メモリ 201,420 KB
最終ジャッジ日時 2025-01-18 13:17:40
ジャッジサーバーID
(参考情報)
judge2 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

struct uns_t {} uns;
template <typename Element, typename Head, typename ...Args>
auto vec(Element init, Head arg, Args ...args) {
    if constexpr (sizeof...(Args) == 0) return std::vector(arg, init);
    else return std::vector(arg, vec(init, args...));
}
template <typename Element, typename Head, typename ...Args>
auto vec(uns_t, Head arg, Args ...args) {
    return vec(Element(), arg, args...);
}

int main() {
    constexpr int64_t inf = INT64_MAX / 4;

    int n, x, y; cin >> n >> x >> y;
    auto a = vec<int>(uns, n);
    for (auto &e : a) cin >> e;

    auto acc_x = vec<int64_t>(uns, n + 1); acc_x[0] = 0;
    for (int i = 0; i < n; ++i) {
        acc_x[i + 1] = acc_x[i] + (x - a[i]);
    }

    auto acc_y = vec<int64_t>(uns, n + 1); acc_y[0] = 0;
    for (int i = 0; i < n; ++i) {
        acc_y[i + 1] = acc_y[i] + (y - a[n - i - 1]);
    }

    auto min_x = vec<tuple<int64_t, int>>(uns, n + 1);
    min_x[0] = make_tuple(0, 0);
    for (int i = 1; i <= n; ++i) {
        min_x[i] = min_x[i - 1];
        if (acc_x[i] < get<0>(min_x[i])) {
            min_x[i] = make_tuple(acc_x[i], i);
        }
    }

    auto min_y = vec<tuple<int64_t, int>>(uns, n + 1);
    min_y[0] = make_tuple(0, 0);
    for (int i = 1; i <= n; ++i) {
        min_y[i] = min_y[i - 1];
        if (acc_y[i] < get<0>(min_y[i])) {
            min_y[i] = make_tuple(acc_y[i], i);
        }
    }

    auto dp_x = vec<int64_t>(uns, n + 1); dp_x[0] = -inf;
    for (int i = 1; i <= n; ++i) {
        dp_x[i] = max(dp_x[i - 1], acc_x[i] - acc_x[get<1>(min_x[i - 1])]);
    }

    auto dp_y = vec<int64_t>(uns, n + 1); dp_y[0] = -inf;
    for (int i = 1; i <= n; ++i) {
        dp_y[i] = max(dp_y[i - 1], acc_y[i] - acc_y[get<1>(min_y[i - 1])]);
    }

    int64_t sum = accumulate(begin(a), end(a), int64_t(0));
    for (int i = 2; i <= n - 1; ++i) {
        cout << (sum + dp_x[i - 1] + dp_y[n - i]) << endl;
    }
}

0