結果

問題 No.127 門松もどき
ユーザー krotonkroton
提出日時 2015-01-06 15:44:58
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 106 ms / 5,000 ms
コード長 658 bytes
コンパイル時間 1,364 ms
コンパイル使用メモリ 144,276 KB
実行使用メモリ 85,344 KB
最終ジャッジ日時 2023-08-25 13:38:50
合計ジャッジ時間 3,641 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,492 KB
testcase_01 AC 2 ms
5,424 KB
testcase_02 AC 2 ms
5,648 KB
testcase_03 AC 2 ms
5,428 KB
testcase_04 AC 106 ms
69,216 KB
testcase_05 AC 2 ms
5,400 KB
testcase_06 AC 10 ms
26,996 KB
testcase_07 AC 3 ms
5,752 KB
testcase_08 AC 2 ms
5,564 KB
testcase_09 AC 2 ms
5,524 KB
testcase_10 AC 2 ms
5,548 KB
testcase_11 AC 3 ms
8,108 KB
testcase_12 AC 58 ms
60,880 KB
testcase_13 AC 76 ms
48,648 KB
testcase_14 AC 70 ms
63,988 KB
testcase_15 AC 94 ms
56,852 KB
testcase_16 AC 67 ms
69,008 KB
testcase_17 AC 76 ms
73,000 KB
testcase_18 AC 65 ms
64,816 KB
testcase_19 AC 40 ms
52,140 KB
testcase_20 AC 40 ms
52,160 KB
testcase_21 AC 19 ms
37,480 KB
testcase_22 AC 101 ms
85,264 KB
testcase_23 AC 103 ms
85,344 KB
testcase_24 AC 81 ms
73,064 KB
testcase_25 AC 95 ms
81,388 KB
testcase_26 AC 48 ms
56,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int N, A[3333];
int dpL[3333][3333], dpR[3333][3333];

int main(){
	cin >> N;
	for(int i=0;i<N;i++)
		cin >> A[i];

	for(int i=0;i<N;i++)
		dpL[i][i] = dpR[i][i] = 1;
	
	for(int delta=1;delta<N;delta++){
		for(int L=0;L+delta<N;L++){
			int R = L + delta;

			dpL[L][R] = dpL[L][R-1];
			if(A[L] < A[R])
				dpL[L][R] = max(dpL[L][R], dpR[L+1][R] + 1);

			dpR[L][R] = dpR[L+1][R];
			if(A[L] > A[R])
				dpR[L][R] = max(dpR[L][R], dpL[L][R-1] + 1);
		}
	}

	int res = 0;
	for(int L=0;L<N;L++)
		res = max(res, dpL[L][N-1]);
	for(int R=0;R<N;R++)
		res = max(res, dpR[0][R]);

	cout << res << endl;
	return 0;
}
0