結果

問題 No.2854 -1 Subsequence
ユーザー mitanimitani
提出日時 2024-08-25 13:58:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 109 ms / 2,000 ms
コード長 989 bytes
コンパイル時間 1,654 ms
コンパイル使用メモリ 174,064 KB
実行使用メモリ 15,060 KB
最終ジャッジ日時 2024-08-25 13:58:18
合計ジャッジ時間 5,208 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
12,684 KB
testcase_01 AC 77 ms
12,212 KB
testcase_02 AC 82 ms
12,588 KB
testcase_03 AC 44 ms
8,320 KB
testcase_04 AC 90 ms
13,760 KB
testcase_05 AC 56 ms
9,856 KB
testcase_06 AC 32 ms
6,944 KB
testcase_07 AC 89 ms
13,448 KB
testcase_08 AC 14 ms
6,940 KB
testcase_09 AC 63 ms
10,456 KB
testcase_10 AC 106 ms
14,900 KB
testcase_11 AC 96 ms
14,920 KB
testcase_12 AC 99 ms
14,928 KB
testcase_13 AC 100 ms
14,880 KB
testcase_14 AC 96 ms
14,964 KB
testcase_15 AC 97 ms
15,000 KB
testcase_16 AC 101 ms
14,980 KB
testcase_17 AC 100 ms
14,996 KB
testcase_18 AC 100 ms
14,964 KB
testcase_19 AC 100 ms
14,992 KB
testcase_20 AC 105 ms
15,060 KB
testcase_21 AC 96 ms
14,988 KB
testcase_22 AC 109 ms
14,996 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 2 ms
6,944 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 2 ms
6,944 KB
testcase_28 AC 1 ms
6,940 KB
testcase_29 AC 2 ms
6,944 KB
testcase_30 AC 2 ms
6,944 KB
testcase_31 AC 2 ms
6,944 KB
testcase_32 AC 2 ms
6,944 KB
testcase_33 AC 2 ms
6,944 KB
testcase_34 AC 1 ms
6,940 KB
testcase_35 AC 2 ms
6,940 KB
testcase_36 AC 2 ms
6,940 KB
testcase_37 AC 2 ms
6,940 KB
testcase_38 AC 1 ms
6,940 KB
testcase_39 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(x) x.begin(), x.end()
#define MOD1 1LL<<61-1
#define MOD2 (1LL<<61)-1
#define MOD3 (1LL<<61-1)
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
//#include <atcoder/all>
//using namespace atcoder;
////using mint=static_modint<998244353>;
//using mint=static_modint<1000000007>;
////using mint=modint;
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
int inf=2147483647;
ll INF=9223372036854775807;
const ld PI=acos(-1);

void yn(bool f){
	if(f)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return;
}

int main(){
	int n;cin>>n;
	vector<int> a(n);
	rep(i,n)cin>>a[i];

	vector<vector<ll>> dp(n+1,vector<ll>(2,-1001001001001001001));

	rep(i,n)dp[i+1][1]=-a[i];

	rep(i,n){
		dp[i+1][0]=max({dp[i][0],dp[i][1]+a[i],dp[i+1][0]});
		dp[i+1][1]=max({dp[i][1],dp[i][0]-a[i],dp[i+1][1]});
	}
	
	cout<<max(dp[n][0],dp[n][1])<<endl;

}
0