結果

問題 No.1368 サイクルの中に眠る門松列
ユーザー 沙耶花沙耶花
提出日時 2021-01-29 21:27:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 881 bytes
コンパイル時間 2,591 ms
コンパイル使用メモリ 204,052 KB
実行使用メモリ 8,120 KB
最終ジャッジ日時 2023-09-09 14:42:17
合計ジャッジ時間 3,522 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 15 ms
4,376 KB
testcase_03 AC 4 ms
4,376 KB
testcase_04 AC 7 ms
4,376 KB
testcase_05 AC 33 ms
7,936 KB
testcase_06 AC 33 ms
7,868 KB
testcase_07 AC 32 ms
8,120 KB
testcase_08 AC 34 ms
7,952 KB
testcase_09 AC 32 ms
8,068 KB
testcase_10 AC 32 ms
7,860 KB
testcase_11 AC 32 ms
7,936 KB
testcase_12 AC 32 ms
7,896 KB
testcase_13 AC 32 ms
7,924 KB
testcase_14 AC 32 ms
7,852 KB
testcase_15 AC 32 ms
7,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000000

bool is_kadomatsu(long long a,long long b,long long c){
	if(a==b||b==c||c==a)return false;
	if(b>a&&b>c)return true;
	if(b<a&&b<c)return true;
	return false;
}

long long get(vector<long long> A){
	vector<long long> dp(A.size()+1,0LL);
	rep(i,A.size()){
		dp[i+1] = max(dp[i+1],dp[i]);
		if(i+3<dp.size()){
			if(is_kadomatsu(A[i],A[i+1],A[i+2])){
				dp[i+3] = max(dp[i+3],dp[i] + A[i]);
			}
		}
	}
	return dp.back();
}

int main(){
	
	int T;
	cin>>T;
	
	rep(_,T){
		int N;
		scanf("%d",&N);
		
		vector<long long> A(N);
		rep(i,N){
			scanf("%lld",&A[i]);
		}
		long long ans = 0LL;
		rep(i,3){
			ans = max(ans,get(A));
			long long t = A.back();
			A.pop_back();
			A.insert(A.begin(),t);
		}
		printf("%lld\n",ans);
	}
		
	
    return 0;
}
0