結果

問題 No.127 門松もどき
ユーザー 沙耶花沙耶花
提出日時 2021-10-26 23:47:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 913 bytes
コンパイル時間 4,200 ms
コンパイル使用メモリ 262,380 KB
実行使用メモリ 495,744 KB
最終ジャッジ日時 2023-07-28 15:50:03
合計ジャッジ時間 21,925 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,376 KB
testcase_06 WA -
testcase_07 AC 2 ms
4,376 KB
testcase_08 WA -
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 4 ms
4,620 KB
testcase_12 AC 762 ms
262,324 KB
testcase_13 AC 1,047 ms
350,836 KB
testcase_14 AC 1,007 ms
320,816 KB
testcase_15 AC 1,456 ms
444,608 KB
testcase_16 AC 915 ms
309,840 KB
testcase_17 AC 1,079 ms
360,028 KB
testcase_18 AC 926 ms
298,112 KB
testcase_19 AC 529 ms
183,280 KB
testcase_20 AC 515 ms
188,460 KB
testcase_21 AC 189 ms
88,332 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

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);
			
			
			
		}
	}
	return max(dp[0][n-1][0],dp[0][n-1][1]);
	
}

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