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