結果

問題 No.209 Longest Mountain Subsequence
ユーザー hirokazu1020hirokazu1020
提出日時 2015-05-15 23:11:00
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 822 ms / 2,000 ms
コード長 1,253 bytes
コンパイル時間 584 ms
コンパイル使用メモリ 76,132 KB
実行使用メモリ 11,396 KB
最終ジャッジ日時 2023-09-20 08:29:53
合計ジャッジ時間 4,225 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 312 ms
11,212 KB
testcase_01 AC 273 ms
11,396 KB
testcase_02 AC 261 ms
11,256 KB
testcase_03 AC 822 ms
11,264 KB
testcase_04 AC 822 ms
11,204 KB
testcase_05 AC 228 ms
11,308 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)rep(k,n)rep(f,2){
			int v=dp[i][j][k][f];
			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