結果
問題 | No.1375 Divide and Update |
ユーザー | sten_san |
提出日時 | 2021-02-06 01:18:20 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 360 ms / 2,000 ms |
コード長 | 1,953 bytes |
コンパイル時間 | 2,161 ms |
コンパイル使用メモリ | 210,764 KB |
実行使用メモリ | 16,640 KB |
最終ジャッジ日時 | 2024-07-02 14:44:16 |
合計ジャッジ時間 | 7,862 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 309 ms
14,848 KB |
testcase_11 | AC | 283 ms
13,824 KB |
testcase_12 | AC | 157 ms
9,088 KB |
testcase_13 | AC | 131 ms
8,064 KB |
testcase_14 | AC | 357 ms
16,384 KB |
testcase_15 | AC | 355 ms
16,496 KB |
testcase_16 | AC | 360 ms
16,384 KB |
testcase_17 | AC | 358 ms
16,460 KB |
testcase_18 | AC | 358 ms
16,456 KB |
testcase_19 | AC | 359 ms
16,512 KB |
testcase_20 | AC | 306 ms
16,640 KB |
ソースコード
#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; } }