結果

問題 No.127 門松もどき
ユーザー aa
提出日時 2015-01-14 11:31:07
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,276 bytes
コンパイル時間 743 ms
コンパイル使用メモリ 70,544 KB
実行使用メモリ 74,152 KB
最終ジャッジ日時 2023-09-04 12:58:51
合計ジャッジ時間 3,786 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,380 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 106 ms
47,524 KB
testcase_17 AC 127 ms
54,444 KB
testcase_18 AC 103 ms
45,644 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
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], dpL[0][n - 1]);

	// 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