結果
問題 | No.127 門松もどき |
ユーザー |
![]() |
提出日時 | 2015-01-14 12:05:51 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 160 ms / 5,000 ms |
コード長 | 1,374 bytes |
コンパイル時間 | 896 ms |
コンパイル使用メモリ | 69,664 KB |
実行使用メモリ | 73,984 KB |
最終ジャッジ日時 | 2024-12-23 21:53:14 |
合計ジャッジ時間 | 3,474 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 23 |
ソースコード
#include <iostream> #include <vector> #include <algorithm> using namespace std; void show(vector< vector<int> > &); int main() { vector< vector<int> > dpL, dpR; 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; }