結果

問題 No.2854 -1 Subsequence
ユーザー 寝癖寝癖
提出日時 2024-08-25 14:22:41
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,619 bytes
コンパイル時間 5,589 ms
コンパイル使用メモリ 315,076 KB
実行使用メモリ 33,828 KB
最終ジャッジ日時 2024-08-25 14:22:51
合計ジャッジ時間 9,466 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 102 ms
28,012 KB
testcase_01 AC 99 ms
26,880 KB
testcase_02 AC 108 ms
27,816 KB
testcase_03 AC 58 ms
16,384 KB
testcase_04 AC 113 ms
30,856 KB
testcase_05 AC 72 ms
20,452 KB
testcase_06 AC 46 ms
12,928 KB
testcase_07 AC 109 ms
29,732 KB
testcase_08 AC 17 ms
6,940 KB
testcase_09 AC 78 ms
22,272 KB
testcase_10 AC 125 ms
33,772 KB
testcase_11 AC 128 ms
33,772 KB
testcase_12 AC 129 ms
33,776 KB
testcase_13 AC 130 ms
33,752 KB
testcase_14 AC 128 ms
33,700 KB
testcase_15 AC 128 ms
33,828 KB
testcase_16 AC 140 ms
33,644 KB
testcase_17 AC 125 ms
33,776 KB
testcase_18 AC 126 ms
33,732 KB
testcase_19 AC 128 ms
33,684 KB
testcase_20 AC 128 ms
33,808 KB
testcase_21 AC 121 ms
33,808 KB
testcase_22 AC 130 ms
33,772 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 2 ms
6,940 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 2 ms
6,944 KB
testcase_31 WA -
testcase_32 AC 2 ms
6,940 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 2 ms
6,944 KB
testcase_36 AC 2 ms
6,940 KB
testcase_37 WA -
testcase_38 AC 2 ms
6,944 KB
testcase_39 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>

namespace neguse {}
using namespace std;
using namespace atcoder;
using namespace neguse;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,n-1,-1)
#define rrepi(i,a,b) for(int i=int(a);i>int(b);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep)(__VA_ARGS__)
#define _each1(i,v) for(auto& i:v)
#define _each2(i,j,v) for(auto& [i,j]:v)
#define each(...) _overload3(__VA_ARGS__,_each2,_each1,)(__VA_ARGS__)

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SORT(x) sort(all(x))
#define RSORT(x) sort(rall(x))
#define REVERSE(x) reverse(all(x))

#define dump(x) cerr << #x << " = " << (x) << '\n'
#define print(x) cout << (x) << '\n'
#define yes(f) cout << ((f) ? "Yes" : "No") << '\n'

#define ge(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define gt(v, x) (int)(upper_bound(all(v), x) - v.begin())
#define le(v, x) (int)(upper_bound(all(v), x) - v.begin())-1
#define lt(v, x) (int)(lower_bound(all(v), x) - v.begin())-1

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

ostream& operator<<(ostream& os, const modint998244353& a) { return os << a.val(); }
ostream& operator<<(ostream& os, const modint1000000007& a) { return os << a.val(); }

template<class T> istream& operator>>(istream& is, vector<T>& vec) { for (T& x : vec) is >> x; return is; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) { for (const T& x : vec) os << x << ' '; return os; }


using namespace neguse;

int main() {
    int N;
    cin >> N;
    vi A(N);
    cin >> A;

    vector dp(N + 1, vector(2, vll(2, -1e18)));
    dp[0][0][0] = 0;
    rep(i, N) {
        rep(j, 2) {
            // A[i]を使う場合
            rep(k, 2) chmax(dp[i + 1][(j + 1) % 2][1], dp[i][j][k] + (j ? A[i] : -A[i]));
            // A[i]を使わない場合
            rep(k, 2) chmax(dp[i + 1][j][k], dp[i][j][k]);
        }
    }

    ll ans = 0;
    rep(i, 2) rep(j, 2) chmax(ans, dp[N][i][j]);
    cout << ans << endl;

    return 0;
}
0