結果

問題 No.209 Longest Mountain Subsequence
ユーザー IL_msta
提出日時 2015-08-15 10:24:52
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 1,649 bytes
コンパイル時間 1,062 ms
コンパイル使用メモリ 86,204 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-18 09:38:37
合計ジャッジ時間 1,238 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 6
権限があれば一括ダウンロードができます

ソースコード

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;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0