結果

問題 No.209 Longest Mountain Subsequence
ユーザー kotatsugamekotatsugame
提出日時 2020-03-04 15:02:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 780 bytes
コンパイル時間 845 ms
コンパイル使用メモリ 68,828 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-22 01:38:30
合計ジャッジ時間 1,177 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 3 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    8 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<utility>
using namespace std;
int T,N;
int A[100];
pair<int,int>L[100],R[100];
main()
{
	cin>>T;
	for(;T--;)
	{
		cin>>N;
		for(int i=0;i<N;i++)cin>>A[i];
		for(int i=0;i<N;i++)
		{
			L[i]=make_pair(1,0);
			for(int j=0;j<i;j++)
			{
				if(A[j]<A[i]&&-L[j].second<A[i]-A[j])
				{
					pair<int,int>p;
					p.first=L[j].first+1;
					p.second=-(A[i]-A[j]);
					L[i]=max(L[i],p);
				}
			}
		}
		for(int i=N;i--;)
		{
			R[i]=make_pair(1,0);
			for(int j=N;--j>i;)
			{
				if(A[j]<A[i]&&-R[j].second<A[i]-A[j])
				{
					pair<int,int>p;
					p.first=R[j].first+1;
					p.second=-(A[i]-A[j]);
					R[i]=max(R[i],p);
				}
			}
		}
		int ans=0;
		for(int i=0;i<N;i++)ans=max(ans,L[i].first+R[i].first-1);
		cout<<ans<<endl;
	}
}
0