結果
問題 |
No.2854 -1 Subsequence
|
ユーザー |
![]() |
提出日時 | 2024-08-25 13:49:07 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 29 ms / 2,000 ms |
コード長 | 747 bytes |
コンパイル時間 | 2,885 ms |
コンパイル使用メモリ | 248,020 KB |
実行使用メモリ | 7,964 KB |
最終ジャッジ日時 | 2024-08-25 13:49:14 |
合計ジャッジ時間 | 4,638 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 40 |
ソースコード
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<(int)(n);i++) #define ALL(v) v.begin(),v.end() typedef long long ll; template <class T> using V=vector<T>; template <class T> using VV=V<V<T>>; ll dp[200200][2]; const ll INF=1e18; int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); int n; cin>>n; V<ll> A(n); rep(i,n) cin>>A[i]; if(n==1){ cout<<-A[0]<<endl; return 0; } rep(i,200200) rep(j,2) dp[i][j]=-INF; dp[0][0]=0; rep(i,n){ dp[i+1][0]=max(dp[i+1][0],dp[i][0]); dp[i+1][0]=max(dp[i+1][0],dp[i][1]+A[i]); dp[i+1][1]=max(dp[i+1][1],dp[i][1]); dp[i+1][1]=max(dp[i+1][1],dp[i][0]-A[i]); } cout<<max(dp[n][0],dp[n][1])<<endl; return 0; }