結果

問題 No.1368 サイクルの中に眠る門松列
ユーザー kotatsugame
提出日時 2021-01-29 21:33:10
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 579 bytes
コンパイル時間 519 ms
コンパイル使用メモリ 68,632 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-27 07:41:30
合計ジャッジ時間 1,802 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 4 WA * 11
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:6:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    6 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<algorithm>
using namespace std;
int T,N;
int A[2<<17];
main()
{
	cin>>T;
	for(;T--;)
	{
		cin>>N;
		for(int i=0;i<N;i++)cin>>A[i];
		A[N]=A[0];
		A[N+1]=A[1];
		long ans=0;
		if(N%3==0)
		{
			for(int i=0;i<3;i++)
			{
				long dp[3]={};
				for(int j=0;j<N;j++)
				{
					dp[(j+1)%3]=max(dp[(j+1)%3],dp[j%3]);
					if(j+3<=N)
					{
						int x=A[i+j],y=A[(i+j+1)%N],z=A[(i+j+2)%N];
						if((x<y&&y>z||x>y&&y<z)&&x!=z)dp[j%3]+=x;
					}
				}
				ans=max(ans,dp[0]);
				ans=max(ans,dp[1]);
				ans=max(ans,dp[2]);
			}
		}
		cout<<ans<<endl;
	}
}
0