結果

問題 No.1375 Divide and Update
ユーザー ninoinuininoinui
提出日時 2021-02-05 23:02:14
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 1,023 bytes
コンパイル時間 2,049 ms
コンパイル使用メモリ 201,912 KB
実行使用メモリ 10,956 KB
最終ジャッジ日時 2023-09-15 10:18:21
合計ジャッジ時間 4,821 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 40 ms
9,920 KB
testcase_11 AC 37 ms
9,392 KB
testcase_12 AC 21 ms
6,472 KB
testcase_13 AC 17 ms
5,896 KB
testcase_14 AC 46 ms
10,888 KB
testcase_15 AC 45 ms
10,864 KB
testcase_16 AC 45 ms
10,920 KB
testcase_17 AC 45 ms
10,884 KB
testcase_18 AC 48 ms
10,868 KB
testcase_19 AC 46 ms
10,884 KB
testcase_20 AC 34 ms
10,956 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

template <class A, class B> bool cmin(A& a, B b) { return a > b && (a = b, true); }
template <class A, class B> bool cmax(A& a, B b) { return a < b && (a = b, true); }

signed main() {
  cin.tie(nullptr)->sync_with_stdio(false);

  long N, X, Y;
  cin >> N >> X >> Y;
  vector<long> A(N);
  for (long i = 0; i < N; i++) cin >> A.at(i);

  auto B = A;
  for (long i = 0; i < N; i++) {
    B.at(i) = X - B.at(i);
  }

  vector<long> L(N);
  for (long i = 0, now = 0, mx = LONG_MIN; i < N; i++) {
    now += B.at(i);
    cmax(mx, now);
    if (now < 0) now = 0;
    L.at(i) = mx;
  }

  auto C = A;
  for (long i = 0; i < N; i++) {
    C.at(i) = Y - C.at(i);
  }

  vector<long> R(N);
  for (long i = N - 1, now = 0, mx = LONG_MIN; i >= 0; i--) {
    now += C.at(i);
    cmax(mx, now);
    if (now < 0) now = 0;
    R.at(i) = mx;
  }

  long acc = accumulate(A.begin(), A.end(), 0L);
  for (long i = 1; i + 1 < N; i++) {
    cout << acc + L.at(i - 1) + R.at(i + 1) << '\n';
  }
}
0