結果

問題 No.209 Longest Mountain Subsequence
ユーザー furafura
提出日時 2020-02-09 00:43:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 60 ms / 2,000 ms
コード長 770 bytes
コンパイル時間 2,006 ms
コンパイル使用メモリ 199,652 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-07-24 10:13:18
合計ジャッジ時間 2,758 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

const int INF=1<<29;

void solve(){
	int n,a[100]; scanf("%d",&n);
	rep(i,n) scanf("%d",&a[i]);

	int dp[2][100][100];
	rep(t,2){
		rep(i,n) rep(j,n) dp[t][i][j]=-INF;

		rep(i,n) dp[t][i][i]=1;
		for(int i=1;i<n;i++) rep(j,i) if(a[j]<a[i]) dp[t][j][i]=2;
		for(int i=2;i<n;i++){
			rep(j,i) if(a[j]<a[i]) rep(k,j) if(a[k]<a[j] && a[j]-a[k]<a[i]-a[j]) {
				dp[t][j][i]=max(dp[t][j][i],dp[t][k][j]+1);
			}
		}
		reverse(a,a+n);
	}

	int ans=0;
	rep(i,n){
		int tmp0=0,tmp1=0;
		rep(j,n){
			tmp0=max(tmp0,dp[0][j][i]);
			tmp1=max(tmp1,dp[1][j][n-i-1]);
		}
		ans=max(ans,tmp0+tmp1-1);
	}
	printf("%d\n",ans);
}

int main(){
	int q; scanf("%d",&q); rep(_,q) solve();
	return 0;
}
0