結果
| 問題 |
No.127 門松もどき
|
| コンテスト | |
| ユーザー |
a
|
| 提出日時 | 2015-01-14 11:40:35 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,284 bytes |
| コンパイル時間 | 763 ms |
| コンパイル使用メモリ | 69,952 KB |
| 実行使用メモリ | 74,112 KB |
| 最終ジャッジ日時 | 2024-06-22 11:35:19 |
| 合計ジャッジ時間 | 3,560 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 15 WA * 8 |
ソースコード
#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;
}
a