結果
問題 | No.2854 -1 Subsequence |
ユーザー |
|
提出日時 | 2024-08-25 14:58:13 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,012 bytes |
コンパイル時間 | 3,001 ms |
コンパイル使用メモリ | 254,248 KB |
実行使用メモリ | 15,836 KB |
最終ジャッジ日時 | 2024-08-25 14:58:45 |
合計ジャッジ時間 | 6,448 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 29 WA * 11 |
ソースコード
#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,vector<ll>(2,-INF)); DP[0][1]=-A[0]; for(int i=0;i<N-1;i++){ ll S=A[i+1]; DP[i+1][0]=max(DP[i][0],DP[i][1]+S); DP[i+1][1]=max(DP[i][1],DP[i][0]-S); } for(auto v:DP){ debug_v(v); } cout << max(DP[N-1][0],DP[N-1][1]) << endl; }