結果

問題 No.1368 サイクルの中に眠る門松列
ユーザー 沙耶花
提出日時 2021-01-29 21:27:43
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 881 bytes
コンパイル時間 2,653 ms
コンパイル使用メモリ 196,948 KB
最終ジャッジ日時 2025-01-18 08:51:27
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 15
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:34:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   34 |                 scanf("%d",&N);
      |                 ~~~~~^~~~~~~~~
main.cpp:38:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   38 |                         scanf("%lld",&A[i]);
      |                         ~~~~~^~~~~~~~~~~~~~

ソースコード

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