結果

問題 No.127 門松もどき
ユーザー 沙耶花沙耶花
提出日時 2021-10-26 23:50:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,558 ms / 5,000 ms
コード長 978 bytes
コンパイル時間 4,729 ms
コンパイル使用メモリ 257,336 KB
実行使用メモリ 495,872 KB
最終ジャッジ日時 2024-04-16 00:14:42
合計ジャッジ時間 22,338 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1,558 ms
495,872 KB
testcase_05 AC 6 ms
6,944 KB
testcase_06 AC 89 ms
42,368 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 4 ms
6,940 KB
testcase_12 AC 809 ms
262,400 KB
testcase_13 AC 1,126 ms
351,104 KB
testcase_14 AC 1,070 ms
320,768 KB
testcase_15 AC 1,547 ms
444,544 KB
testcase_16 AC 1,018 ms
310,272 KB
testcase_17 AC 1,129 ms
360,192 KB
testcase_18 AC 957 ms
298,112 KB
testcase_19 AC 538 ms
183,296 KB
testcase_20 AC 516 ms
188,416 KB
testcase_21 AC 193 ms
88,320 KB
testcase_22 AC 1,428 ms
495,872 KB
testcase_23 AC 1,424 ms
495,872 KB
testcase_24 AC 1,176 ms
380,288 KB
testcase_25 AC 1,305 ms
449,536 KB
testcase_26 AC 651 ms
222,336 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 1000000000

int get(vector<int> a){
	int n = a.size();
	vector dp(n,vector(n,vector<int>(2,-Inf)));
	rep(i,n){
		dp[i][i][0] = 1;
		dp[i][i][1] = 1;
	}
	
	for(int i=2;i<=n;i++){
		rep(j,n){
			int l = j;
			int r = j+i-1;
			if(r>=n)break;
			
			dp[l][r][0] = max(dp[l][r][0],dp[l][r-1][0]);
			if(a[r]>a[l])dp[l][r][0] = max(dp[l][r][0],dp[l+1][r][1]+1);
			dp[l][r][1] = max(dp[l][r][1],dp[l+1][r][1]);
			if(a[l]>a[r])dp[l][r][1] = max(dp[l][r][1],dp[l][r-1][0]+1);
			
			
			
		}
	}
	int ret = 0;
	rep(i,n){
		rep(j,n){
			rep(k,2){
				ret = max(ret,dp[i][j][k]);
			}
		}
	}
	return ret;
	
}

int main(){
	
	int n;
	cin>>n;
	
	vector<int> a(n);
	rep(i,n)cin>>a[i];
	
	int ans = get(a);
	rep(i,n)a[i] *= -1;
//	ans = max(ans,get(a));
	
	cout<<ans<<endl;
	
	return 0;
}
0