結果

問題 No.127 門松もどき
ユーザー aa
提出日時 2015-01-14 12:01:50
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 146 ms / 5,000 ms
コード長 1,373 bytes
コンパイル時間 795 ms
コンパイル使用メモリ 70,808 KB
実行使用メモリ 74,012 KB
最終ジャッジ日時 2023-08-25 13:42:35
合計ジャッジ時間 3,593 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 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,376 KB
testcase_04 AC 145 ms
73,948 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 9 ms
8,944 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 72 ms
40,764 KB
testcase_13 AC 98 ms
53,236 KB
testcase_14 AC 89 ms
48,844 KB
testcase_15 AC 127 ms
66,576 KB
testcase_16 AC 85 ms
47,356 KB
testcase_17 AC 103 ms
54,716 KB
testcase_18 AC 83 ms
45,668 KB
testcase_19 AC 52 ms
29,164 KB
testcase_20 AC 50 ms
29,976 KB
testcase_21 AC 21 ms
15,520 KB
testcase_22 AC 144 ms
73,920 KB
testcase_23 AC 146 ms
74,012 KB
testcase_24 AC 107 ms
57,372 KB
testcase_25 AC 133 ms
67,268 KB
testcase_26 AC 61 ms
34,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

void show(vector< vector<int> > &);

vector< vector<int> > dpL, dpR;

int main() {
	vector<int> a;
	int n;

	cin >> n;
	a.assign(n, 0);

	int input;
	for (int i = 0; i < n; i++) {
		cin >> input;
		a[i] = input;
	}

	dpL.assign(n, vector<int>(n, 0));
	dpR = dpL;

	for (int i = 0; i < n; i++) {
		dpR[i][i] = 1;
		dpL[i][i] = 1;
	}

	for (int diff = 1; diff < n; diff++) {
		for (int left = 0; left < n; left++) {
			int right = left + diff;
			if (right >= n) {
				break;
			}

			if (a[left] >= a[right]) {
				dpL[left][right] = dpL[left][right - 1];
			} else {
				dpL[left][right] = max(dpL[left][right - 1], dpR[left + 1][right] + 1);
			}

			if (a[right] >= a[left]) {
				 dpR[left][right] = dpR[left + 1][right];
			} else {
				 dpR[left][right] = max(dpR[left + 1][right], dpL[left][right - 1] + 1);
			}
		}
	} 

	int ans = 0;
	for (int i = 0; i < n; i++) {
		ans = max(ans, dpL[i][n - 1]);
		ans = max(ans, dpR[0][n - 1 - i]);
	}

	cout << ans << endl;

	// cout << endl << endl << "dpL" << endl;;
	// show(dpL);
	// cout << endl << "dpR" << endl;
	// show(dpR);

	return 0;
}

void show(vector< vector<int> > &vec2) {
	int n = vec2.size();
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			printf("%2d ", vec2[i][j]);
		}
		cout << endl;
	}
	cout << endl;
}
0