結果

問題 No.2854 -1 Subsequence
ユーザー graph11463graph11463
提出日時 2024-08-25 14:46:21
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,972 bytes
コンパイル時間 3,338 ms
コンパイル使用メモリ 253,716 KB
実行使用メモリ 15,836 KB
最終ジャッジ日時 2024-08-25 14:46:28
合計ジャッジ時間 6,663 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 75 ms
12,868 KB
testcase_02 WA -
testcase_03 AC 44 ms
8,704 KB
testcase_04 WA -
testcase_05 AC 54 ms
10,240 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 95 ms
15,724 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 95 ms
15,816 KB
testcase_14 WA -
testcase_15 AC 96 ms
15,688 KB
testcase_16 WA -
testcase_17 AC 95 ms
15,756 KB
testcase_18 WA -
testcase_19 AC 95 ms
15,836 KB
testcase_20 AC 105 ms
15,760 KB
testcase_21 WA -
testcase_22 AC 105 ms
15,680 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,940 KB
testcase_31 WA -
testcase_32 AC 2 ms
6,944 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 1 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>
using namespace std;
//ループ系マクロ
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REP2(i, s, n) for (ll i = s; i < (ll)n; i++)
#define REP3(v, A) for(auto v: A)
#define REP4(It, A) for (ll It=A.begin();It!=A.end();++It)
#define REP5(i, n) for (ll i = 0; i * i < (ll)(n); i++)
//vector系マクロ
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
#define SORT(A) sort(ALL(A))
#define RSORT(A) sort(RALL(A))
//入力系マクロ
#define GET(A) cin >> A
#define GETV(i,n,A) REP(i,n)cin >> A[i] 
//出力系マクロ
#define print(A) cout << A << endl
#define YeNo(bo) print(((bo) ? "Yes":"No"))
#define YENO(bo) print(((bo) ? "YES":"NO"))
#define yeno(bo) print(((bo) ? "yes":"no"))
#define LISTOUT(A) rep(i,A.size())cout << A[i] << " ";cout << endl
//雑処理系マクロ
#define PB push_back
#define IS insert
#define SZ size
#define TE true
#define FE false
#define Fir first
#define Sec second
//定数系マクロ
#define I_MAX 2147483647
#define I_MIN -2147483647
#define UI_MAX 4294967295
#define LL_MAX 9223372036854775807
#define LL_MIN -9223372036854775808
#define ULL_MAX 18446744073709551615
//型宣言系マクロ
using ll = long long;
using ull =unsigned long long;
using P = pair<int,int>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
//using mint = modint998244353;
//デバッグ系マクロ
#ifdef _DEBUG
    #define debug(x) cerr << "dbg: "<< #x << ": " << x << endl
    #define debug_v(x)  cerr << "dbg_vec: " << #x << ": "; REP3(v,x) cerr << v << " "; cerr << endl
    #define debug_s(x)  cerr << "dbg_set: " << #x << ": {"; REP3(v,x) cerr << v << ","; cerr << "}" << endl
    #define debug_m(x)  cerr << "dbg_map: " << #x << ": "; REP4(Ite1,x)cerr << "key: " << Ite1->first << " : " << Ite1->second << " "; cerr<< endl
#else
    #define debug(x)
    #define debug_v(x)
    #define debug_s(x)
    #define debug_m(x)
#endif
//関数系マクロ
ll GCM(ll a,ll b){
    if(b==0){
        return a;
    }
    return GCM(b,b%a);
}
bool kaibuncheck(string S){
    bool ret=TE;
    REP(i,S.SZ()/2){
        if(S[i]!=S[S.SZ()-i-1]){
            ret=FE;
            break;
        }
    }
    return ret;
}
vector<pair<ll,ll>> primefact(ll N){
    vector<pair<ll,ll>> ret;
    REP5(i,N){
        ll cot=0;
        if(N%i==0){
            while(N%i==0){
                cot++;
                N/=i;
            }
            ret.PB(make_pair(i,cot));
        }
    }
    if(N!=1)ret.PB(make_pair(N,1));
    return ret;
}
ll fun(ll N){
    if(N%2==0){
        return 1;
    }else{
        return -1;
    }
}
int main() {
    ll N;cin >> N;
    vector<ll> A(N);
    GETV(i,N,A);
    ll INF=1e18;
    vector<vector<ll>> DP(N+1,vector<ll>(2,-INF));
    DP[0][0]=0;
    DP[0][1]=0;
    for(int i=0;i<N;i++){
        ll S=A[i];
        DP[i+1][0]=max(DP[i][0],DP[i][1]+S);
        DP[i+1][1]=max(DP[i][1],DP[i][0]-S);
    }
    cout << max(DP[N][0],DP[N][1]) << endl;
}
0