結果

問題 No.209 Longest Mountain Subsequence
ユーザー IL_mstaIL_msta
提出日時 2015-08-15 10:24:52
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 14 ms / 2,000 ms
コード長 1,649 bytes
コンパイル時間 1,520 ms
コンパイル使用メモリ 85,584 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-25 12:01:15
合計ジャッジ時間 1,417 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#define _USE_MATH_DEFINES
 
#include <iostream>
#include <iomanip>
#include <sstream>
 
#include <algorithm>
#include <cmath>
 
#include <string>
//#include <array>
#include <list>
#include <queue>
#include <vector>
#include <complex>
#include <set>
#include <map>
 
/////////
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
 
#define PII pair<int,int>
/////////
typedef long long LL;
typedef long double LD;
/////////
using namespace::std;
/////////
#define MAX_P 101
const LL INF = (LL)1e10+10;
LL dd[MAX_P+1][MAX_P+1];

void getLIS_M(LL* a,LL n,LL* dp){
	fill(dp, dp + MAX_P + 1, INF);
	rep(i,MAX_P+1)rep(j,MAX_P+1){
		if( j > 1){
			dd[i][j] = INF;
		}else{
			dd[i][j] = 0;
		}
	}
	LL sa;
	for(int i= 0; i< n; ++i){
		dp[i] = 1;
		for(int j = 0; j < i; ++j){
			if( a[j] < a[i] ){
				sa = a[i]-a[j];
				for(int k=1; k<=dp[j];++k){
					if( sa > dd[j][ k ] ){//
						if( dp[i] < k + 1 ){
							dp[i] = k + 1;
						}
						dd[i][k+1] = min( dd[i][k+1], sa );
					}
				}
			}
		}
	}
	return ;
}

LL f(LL* a,LL* ra,LL N){
	LL dp[MAX_P+1],rdp[MAX_P+1];
	LL ans = 0;
	getLIS_M( a,N, dp);
	getLIS_M(ra,N,rdp);
	for(int i=0;i<N; ++i){
		ans = max( ans,dp[i] + rdp[N-1-i] );
	}
	return ans - 1;
}
int main(void){
    std::cin.tie(0); 
    std::ios::sync_with_stdio(false);
    std::cout << std::fixed;//
    //cout << setprecision(16);//
	
	int T;
	cin>>T;
	LL N;
	LL a[100],ra[100];
	LL ans[100];
	fill(ans, ans + 100, 0);
	rep(i,T){
		cin>>N;
		ans[i] = 0;
		rep(j,N){
			cin>>a[j];
			ra[N-j-1] = a[j];
		}

		ans[i] = f(a,ra,N);
	}
	rep(i,T){
		cout << ans[i] << endl;
	}
	return 0;
}
0