結果

問題 No.1368 サイクルの中に眠る門松列
ユーザー kotatsugamekotatsugame
提出日時 2021-01-29 21:37:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 470 bytes
コンパイル時間 479 ms
コンパイル使用メモリ 66,268 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-09 14:55:46
合計ジャッジ時間 2,616 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 39 ms
4,380 KB
testcase_03 AC 9 ms
4,376 KB
testcase_04 AC 14 ms
4,380 KB
testcase_05 AC 63 ms
4,380 KB
testcase_06 AC 63 ms
4,380 KB
testcase_07 AC 63 ms
4,380 KB
testcase_08 AC 62 ms
4,380 KB
testcase_09 AC 49 ms
4,376 KB
testcase_10 AC 48 ms
4,384 KB
testcase_11 AC 49 ms
4,376 KB
testcase_12 AC 51 ms
4,376 KB
testcase_13 AC 52 ms
4,376 KB
testcase_14 AC 50 ms
4,380 KB
testcase_15 AC 49 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:6:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-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];
		long ans=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[N%3]);
		}
		cout<<ans<<endl;
	}
}
0