結果

問題 No.127 門松もどき
ユーザー 沙耶花沙耶花
提出日時 2021-10-26 23:44:51
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 911 bytes
コンパイル時間 4,516 ms
コンパイル使用メモリ 257,820 KB
実行使用メモリ 495,872 KB
最終ジャッジ日時 2024-04-16 00:08:29
合計ジャッジ時間 37,388 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,812 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 WA -
testcase_05 AC 2 ms
6,940 KB
testcase_06 WA -
testcase_07 AC 3 ms
6,944 KB
testcase_08 WA -
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 5 ms
6,940 KB
testcase_12 AC 1,500 ms
262,416 KB
testcase_13 AC 2,273 ms
350,976 KB
testcase_14 AC 1,982 ms
320,788 KB
testcase_15 AC 2,804 ms
444,576 KB
testcase_16 AC 1,883 ms
310,288 KB
testcase_17 AC 2,112 ms
360,216 KB
testcase_18 AC 1,863 ms
298,004 KB
testcase_19 AC 1,044 ms
183,168 KB
testcase_20 AC 1,012 ms
188,288 KB
testcase_21 AC 325 ms
88,448 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