結果

問題 No.2854 -1 Subsequence
ユーザー manabeaimanabeai
提出日時 2024-08-25 15:44:36
言語 C++23(gcc13)
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,272 bytes
コンパイル時間 6,204 ms
コンパイル使用メモリ 337,476 KB
実行使用メモリ 14,668 KB
最終ジャッジ日時 2024-08-25 15:44:47
合計ジャッジ時間 10,500 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 106 ms
13,764 KB
testcase_02 WA -
testcase_03 AC 61 ms
8,704 KB
testcase_04 WA -
testcase_05 AC 77 ms
9,088 KB
testcase_06 AC 44 ms
6,940 KB
testcase_07 WA -
testcase_08 AC 18 ms
6,944 KB
testcase_09 AC 85 ms
9,216 KB
testcase_10 AC 137 ms
14,500 KB
testcase_11 AC 137 ms
14,588 KB
testcase_12 AC 138 ms
14,520 KB
testcase_13 AC 137 ms
14,512 KB
testcase_14 AC 137 ms
14,632 KB
testcase_15 AC 137 ms
14,652 KB
testcase_16 AC 137 ms
14,528 KB
testcase_17 AC 137 ms
14,520 KB
testcase_18 AC 137 ms
14,496 KB
testcase_19 AC 137 ms
14,516 KB
testcase_20 AC 142 ms
14,528 KB
testcase_21 AC 132 ms
14,668 KB
testcase_22 AC 144 ms
14,520 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 AC 2 ms
6,944 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 2 ms
6,940 KB
testcase_28 AC 2 ms
6,940 KB
testcase_29 AC 1 ms
6,940 KB
testcase_30 AC 2 ms
6,944 KB
testcase_31 AC 2 ms
6,940 KB
testcase_32 AC 2 ms
6,944 KB
testcase_33 AC 2 ms
6,944 KB
testcase_34 AC 2 ms
6,944 KB
testcase_35 AC 2 ms
6,944 KB
testcase_36 AC 2 ms
6,940 KB
testcase_37 AC 2 ms
6,940 KB
testcase_38 AC 1 ms
6,940 KB
testcase_39 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/all>
#include <bits/stdc++.h>
#ifdef DEBUG
#include "cpp-dump/dump.hpp"
#define dump(...) cpp_dump(__VA_ARGS__)
#else
#define dump(...)
#endif
using namespace std;
using namespace atcoder;
typedef long long ll;
const ll INF = 2 * 1e18;

ll op1 (ll a, ll b) {return max(a,b);}
ll e1() {return -INF;}
ll op2 (ll a, ll b) {return min(a,b);}
ll e2() {return INF;}


void solve() {
    ll n;
    cin >> n;
    vector<ll> A(n);
    for (ll i = 0; i < n; ++i) cin >> A[i];
    vector<ll> t(n, -INF);
    // vector<ll> ans(n);

    segtree<ll, op1, e1> segmin(t);
    segtree<ll, op1, e1> segplus(t);
    segmin.set(0, A[0]*(-1));

    if (n == 1) {
        cout << A[0]*(-1) << endl;
        return;
    }
    
    // iにマイナスがかかるときとプラスがかかるときを別に計算する
    for (ll i = 1; i < n; ++i) {
        ll t = segmin.prod(0, i);
        segplus.set(i, A[i]+t);
        t = segplus.prod(0,i);
        // if (t == -INF) continue;
        if (1 == i) {
            segmin.set(i, A[i]*(-1));
        } else {
            segmin.set(i, t + A[i]*(-1));
        }
    }

    ll ans = max(segmin.all_prod(), segplus.all_prod());
    assert(ans != -INF * 2);
    cout << ans << endl;
}

int main() {
    solve();
    return 0;
}
0