結果
問題 | No.127 門松もどき |
ユーザー |
![]() |
提出日時 | 2015-01-14 08:54:50 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 118 ms / 5,000 ms |
コード長 | 1,162 bytes |
コンパイル時間 | 786 ms |
コンパイル使用メモリ | 73,704 KB |
実行使用メモリ | 74,240 KB |
最終ジャッジ日時 | 2024-12-23 21:51:45 |
合計ジャッジ時間 | 3,425 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 23 |
ソースコード
#include <sstream> #include <string> #include <vector> #include <map> #include <algorithm> #include <iostream> #include <utility> #include <set> #include <cctype> #include <queue> #include <stack> #include <cstdio> #include <cstdlib> #include <cmath> #define INF 1000000000 using namespace std; typedef long long ll; const int MAXN = 3010; int A[MAXN]; int dpL[MAXN][MAXN]; int dpR[MAXN][MAXN]; int main(void) { int N; int ret = 1; cin >> N; for (int i = 0; i < N; i++) { cin >> A[i]; } for (int i = 0; i < MAXN; i++) for (int j = 0; j < MAXN; j++) { dpL[i][j] = dpR[i][j] = 1; } for (int w = 1; w < N; w++) { for (int x = 0; x+w < N; x++) { dpL[x][x+w] = max(dpL[x][x+w], dpL[x][x+w-1]); dpR[x][x+w] = max(dpR[x][x+w], dpR[x+1][x+w]); if (A[x] < A[x+w]) { dpL[x][x+w] = max(dpL[x][x+w], 1 + dpR[x+1][x+w]); } if (A[x] > A[x+w]) { dpR[x][x+w] = max(dpR[x][x+w], dpL[x][x+w-1]+1); } ret = max(ret, max(dpL[x][x+w], dpR[x][x+w])); } } cout << ret << endl; return 0; }