結果

問題 No.127 門松もどき
ユーザー aa
提出日時 2015-01-14 11:40:35
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,284 bytes
コンパイル時間 1,298 ms
コンパイル使用メモリ 71,432 KB
実行使用メモリ 74,196 KB
最終ジャッジ日時 2023-09-04 13:00:42
合計ジャッジ時間 4,145 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,384 KB
testcase_06 WA -
testcase_07 AC 2 ms
4,376 KB
testcase_08 WA -
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 88 ms
40,552 KB
testcase_13 AC 123 ms
53,180 KB
testcase_14 AC 112 ms
48,968 KB
testcase_15 AC 166 ms
66,600 KB
testcase_16 AC 107 ms
47,388 KB
testcase_17 AC 127 ms
54,496 KB
testcase_18 AC 104 ms
45,616 KB
testcase_19 AC 60 ms
29,168 KB
testcase_20 AC 62 ms
30,084 KB
testcase_21 AC 26 ms
15,544 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

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);
			}
		}
	} 

	cout << max(dpL[0][n - 1], dpR[0][n - 1]) << 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