結果

問題 No.127 門松もどき
ユーザー 沙耶花沙耶花
提出日時 2021-10-26 23:50:47
言語 C++17
(gcc 12.2.0 + boost 1.81.0)
結果
AC  
実行時間 1,429 ms / 5,000 ms
コード長 978 bytes
コンパイル時間 5,345 ms
コンパイル使用メモリ 264,084 KB
実行使用メモリ 495,428 KB
最終ジャッジ日時 2023-07-28 15:53:55
合計ジャッジ時間 21,319 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1,380 ms
495,316 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 85 ms
42,112 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 4 ms
4,456 KB
testcase_12 AC 759 ms
262,480 KB
testcase_13 AC 1,040 ms
350,756 KB
testcase_14 AC 1,004 ms
320,672 KB
testcase_15 AC 1,429 ms
444,536 KB
testcase_16 AC 930 ms
309,824 KB
testcase_17 AC 1,071 ms
359,996 KB
testcase_18 AC 907 ms
297,916 KB
testcase_19 AC 530 ms
183,256 KB
testcase_20 AC 503 ms
187,988 KB
testcase_21 AC 196 ms
88,052 KB
testcase_22 AC 1,379 ms
495,428 KB
testcase_23 AC 1,372 ms
495,388 KB
testcase_24 AC 1,133 ms
380,220 KB
testcase_25 AC 1,258 ms
449,416 KB
testcase_26 AC 637 ms
222,224 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