結果

問題 No.209 Longest Mountain Subsequence
ユーザー hirokazu1020hirokazu1020
提出日時 2015-05-15 23:14:49
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 357 ms / 2,000 ms
コード長 1,286 bytes
コンパイル時間 585 ms
コンパイル使用メモリ 76,480 KB
実行使用メモリ 11,400 KB
最終ジャッジ日時 2023-09-20 08:30:30
合計ジャッジ時間 2,470 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 163 ms
11,400 KB
testcase_01 AC 134 ms
11,396 KB
testcase_02 AC 132 ms
11,272 KB
testcase_03 AC 353 ms
11,340 KB
testcase_04 AC 357 ms
11,372 KB
testcase_05 AC 104 ms
11,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<sstream>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())
#define indexOf(v,x) (find(all(v),x)-v.begin())



int t,n,a[100];
int dp[101][100][100][2];


int main(){
	cin>>t;
	rep(donuts,t){
		cin>>n;
		rep(i,n)cin>>a[i];
		memset(dp,0,sizeof(dp));
		int ans=min(n,2);
		rep(j,n)rep(i,j){
			if(a[i]>a[j]){
				dp[j+1][i][j][1]=2;
			}else if(a[i]<a[j]){
				dp[j+1][i][j][0]=2;
			}
		}
		rep(i,n)rep(j,n)for(int k=j+1;k<n;k++)rep(f,2){
			int v=dp[i][j][k][f];
			if(!v)continue;
			dp[i+1][j][k][f]=max(dp[i+1][j][k][f],v);
			if(!f){
				if(a[k]<a[i] && abs(a[j]-a[k])<abs(a[k]-a[i])){
					dp[i+1][k][i][0]=max(dp[i+1][k][i][0],v+1);
					ans=max(ans,v+1);
				}
				if(a[k]>a[i]){
					dp[i+1][k][i][1]=max(dp[i+1][k][i][1],v+1);
					ans=max(ans,v+1);
				}
			}else if(a[k]>a[i] && abs(a[j]-a[k])>abs(a[k]-a[i])){
				dp[i+1][k][i][1]=max(dp[i+1][k][i][1],v+1);
				ans=max(ans,v+1);
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}
0