結果

問題 No.209 Longest Mountain Subsequence
ユーザー 沙耶花沙耶花
提出日時 2021-11-04 20:06:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 118 ms / 2,000 ms
コード長 916 bytes
コンパイル時間 4,571 ms
コンパイル使用メモリ 256,908 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-23 02:45:48
合計ジャッジ時間 5,188 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint1000000007;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000000000000
	
vector<int> get(vector<int> a){
	int n = a.size();
	vector<int> ret(n,0);
	vector dp(n,vector<long long>(n+1,Inf));
	rep(i,n){
		dp[i][1] = 0;
		rep(j,n+1){
			if(j==0)continue;
			rep(k,i){
				if(dp[k][j-1] < a[i] - a[k]){
					dp[i][j] = min(dp[i][j],(long long)a[i]-a[k]);
				}
			}
			
		}
	}
	rep(i,n){
		rep(j,n+1){
			if(dp[i][j]==Inf)continue;
			ret[i] = j;
		}
	}
	return ret;
}

int main(){	
	
	int _t;
	cin>>_t;
	
	rep(_,_t){
		int N;
		cin>>N;
		
		vector<int> A(N);
		rep(i,N)cin>>A[i];
		
		auto a = get(A);
		reverse(A.begin(),A.end());
		auto b = get(A);
		reverse(b.begin(),b.end());
		int ans = 0;
		rep(i,N)ans = max(ans,a[i]+b[i]-1);
		cout<<ans<<endl;
	}

	return 0;
	
}
0