結果

問題 No.3185 Three Abs
ユーザー yamate11
提出日時 2025-06-20 22:22:43
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,550 bytes
コンパイル時間 2,903 ms
コンパイル使用メモリ 279,640 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2025-06-20 22:22:52
合計ジャッジ時間 7,573 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other WA * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <cassert>
using namespace std;
using ll = long long int;
using u64 = unsigned long long;
using pll = pair<ll, ll>;
// #include <atcoder/all>
// using namespace atcoder;
#define REP(i, a, b) for (ll i = (a); i < (b); i++)
#define REPrev(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(coll) (coll).begin(), (coll).end()
#define SIZE(v) ((ll)((v).size()))
#define REPOUT(i, a, b, exp, sep) REP(i, (a), (b)) cout << (exp) << (i + 1 == (b) ? "" : (sep)); cout << "\n"

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  auto solve = [&]() -> void {
    ll N; cin >> N;
    // @InpVec(N, A) [2w6s3FHV]
    auto A = vector(N, ll());
    for (int i = 0; i < N; i++) { ll v; cin >> v; A[i] = v; }
    // @End [2w6s3FHV]
    vector<ll> L(N + 1, 0LL);
    vector<ll> Lx(N + 1, 0LL);
    vector<ll> Ln(N + 1, 0LL);
    vector<ll> R(N + 1, 0LL);
    REP(i, 0, N) L[i + 1] = L[i] + A[i];
    REPrev(i, N - 1, 0) R[i] = R[i + 1] + A[i];
    Lx[1] = Ln[1] = L[1];
    REP(i, 1, N) Lx[i + 1] = max(Lx[i], L[i + 1]);
    REP(i, 1, N) Ln[i + 1] = min(Lx[i], L[i + 1]);
    ll ans = 0;
    REP(i, 2, N) {
      ll right = abs(R[i]);
      ll x1 = Lx[i - 1];
      ll x2 = L[i] - x1;
      ll y1 = Ln[i - 1];
      ll y2 = L[i] - y1;
      ll a = max(abs(x1) + abs(x2), abs(y1) + abs(y2));
      ll val = a + right;
      ans = max(ans, val);
    }
    cout << ans << "\n";
  };

  ll T; cin >> T;
  REP(t, 0, T) solve();

  return 0;
}

0