結果

問題 No.3185 Three Abs
ユーザー 沙耶花
提出日時 2025-06-20 21:29:57
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 464 ms / 2,000 ms
コード長 913 bytes
コンパイル時間 3,826 ms
コンパイル使用メモリ 255,612 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-06-20 21:30:13
合計ジャッジ時間 15,265 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000005
#define Inf64 4000000000000000001LL

int main(){
	
	int _t;
	cin>>_t;
	rep(_,_t){
		int n;
		cin>>n;
		vector<int> a(n);
		rep(i,n)cin>>a[i];
		vector dp(2,vector<long long>(3,-Inf64));
		dp[0][0] = a[0];
		dp[1][0] = -a[0];
		for(int i=1;i<n;i++){
			vector ndp(2,vector<long long>(3,-Inf64));
			rep(j,2){
				rep(k,3){
					rep(l,2){
						int nj = l;
						int nk = k;
						if(j!=l)nk++;
						if(nk==3)continue;
						long long nv = dp[j][k];
						if(l==0)nv += a[i];
						else nv -= a[i];
						ndp[nj][nk] = max(ndp[nj][nk],nv);
					}
				}
			}
			swap(dp,ndp);
		}
		long long ans = 0;
		rep(i,2){
			rep(j,3){
				ans = max(ans,dp[i][j]);
			}
		}
		cout<<ans<<endl;
	}
	
	return 0;
}
0