結果

問題 No.1368 サイクルの中に眠る門松列
ユーザー hongrockhongrock
提出日時 2021-01-29 21:37:28
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 1,255 bytes
コンパイル時間 1,400 ms
コンパイル使用メモリ 164,112 KB
実行使用メモリ 5,908 KB
最終ジャッジ日時 2023-09-09 14:55:49
合計ジャッジ時間 2,573 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 13 ms
4,376 KB
testcase_03 AC 4 ms
4,376 KB
testcase_04 AC 6 ms
4,380 KB
testcase_05 AC 26 ms
5,828 KB
testcase_06 AC 27 ms
5,808 KB
testcase_07 AC 26 ms
5,804 KB
testcase_08 AC 25 ms
5,908 KB
testcase_09 AC 25 ms
5,860 KB
testcase_10 AC 24 ms
5,852 KB
testcase_11 AC 26 ms
5,844 KB
testcase_12 AC 25 ms
5,844 KB
testcase_13 AC 25 ms
5,848 KB
testcase_14 AC 24 ms
5,848 KB
testcase_15 AC 26 ms
5,836 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define rep(i, a, n) for(int i=(a); i<(n); ++i)
#define per(i, a, n) for(int i=(a); i>(n); --i)
#define pb emplace_back
#define mp make_pair
#define clr(a, b) memset(a, b, sizeof(a))
#define all(x) (x).begin(),(x).end()
#define lowbit(x) (x & -x)
#define fi first
#define se second
#define lson o<<1
#define rson o<<1|1
#define gmid l[o]+r[o]>>1

using LL = long long;
using ULL = unsigned long long;
using pii = pair<int,int>;
using PLL = pair<LL, LL>;
using UI = unsigned int;

const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1.0);

const int N = 2e5 + 10;

int T, n, a[N];
LL dp[N];

bool ok(int p){
	if(a[p-1] == a[p+1])	return 0;
	if(a[p-1] > a[p] && a[p] < a[p+1])	return 1;
	if(a[p-1] < a[p] && a[p] > a[p+1])	return 1;
	return 0;
}

LL cal(int st){
	rep(i, 0, n + 1){
		dp[i] = 0;	
	}
	rep(i, 0, n){
		dp[i+1] = max(dp[i+1], dp[i]);
		if(ok(st + i + 1)){
			dp[i+3] = max(dp[i+3], dp[i] + a[st + i]);
		}
	}
	return dp[n];
}

int main(){
	scanf("%d", &T);
	while(T--){
		scanf("%d", &n);
		rep(i, 0, n)	scanf("%d", a+i);
		a[n] = a[0];
		a[n+1] = a[1];

		LL ans = 0;
		rep(i, 0, 3)	ans = max(ans, cal(i));
		printf("%lld\n", ans);
	}
	return 0;
}
0