結果

問題 No.1375 Divide and Update
ユーザー sten_sansten_san
提出日時 2021-02-06 01:18:20
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 356 ms / 2,000 ms
コード長 1,953 bytes
コンパイル時間 2,192 ms
コンパイル使用メモリ 206,980 KB
実行使用メモリ 16,704 KB
最終ジャッジ日時 2023-09-15 11:06:58
合計ジャッジ時間 7,866 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 308 ms
14,860 KB
testcase_11 AC 273 ms
13,576 KB
testcase_12 AC 153 ms
9,116 KB
testcase_13 AC 126 ms
7,824 KB
testcase_14 AC 340 ms
16,468 KB
testcase_15 AC 342 ms
16,348 KB
testcase_16 AC 354 ms
16,536 KB
testcase_17 AC 342 ms
16,424 KB
testcase_18 AC 347 ms
16,352 KB
testcase_19 AC 356 ms
16,704 KB
testcase_20 AC 306 ms
16,704 KB
権限があれば一括ダウンロードができます

ソースコード

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