結果

問題 No.209 Longest Mountain Subsequence
ユーザー 👑 kmjpkmjp
提出日時 2015-05-15 22:34:15
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 1,416 bytes
コンパイル時間 1,826 ms
コンパイル使用メモリ 146,680 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-20 08:20:49
合計ジャッジ時間 1,954 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
4,384 KB
testcase_01 AC 21 ms
4,384 KB
testcase_02 AC 19 ms
4,384 KB
testcase_03 AC 65 ms
4,384 KB
testcase_04 AC 65 ms
4,380 KB
testcase_05 AC 6 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<to;x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int T,N,A[1010];
int L[101][101];
int R[101][101];

int left(int LL,int RR) {
	int& ret=L[LL][RR];
	int x;
	if(ret<0) {
		ret=0;
		FOR(x,LL) if(A[x]<A[LL] && A[LL]-A[x]<A[RR]-A[LL]) ret=max(ret,left(x,LL)+1);
	}
	return ret;
}
int right(int LL,int RR) {
	int& ret=R[LL][RR];
	int x;
	if(ret<0) {
		ret=0;
		for(x=RR+1;x<N;x++) if(A[x]<A[RR] && A[RR]-A[x]<A[LL]-A[RR]) ret=max(ret,right(RR,x)+1);
	}
	return ret;
}

int dodo(int i) {
	int x;
	int lm=0,rm=0;
	FOR(x,i) if(A[x]<A[i]) lm=max(lm,left(x,i)+1);
	for(x=i+1;x<N;x++) if(A[x]<A[i]) rm=max(rm,right(i,x)+1);
	return lm+rm+1;
}


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) cin>>A[i];
	
	MINUS(L);
	MINUS(R);
	int ma=-1;
	FOR(i,N) ma=max(ma,dodo(i));
	cout<<ma<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cin>>T;
	while(T--) solve();
	return 0;
}
0