結果
| 問題 | 
                            No.127 門松もどき
                             | 
                    
| コンテスト | |
| ユーザー | 
                             tubo28
                         | 
                    
| 提出日時 | 2015-01-15 16:04:34 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 256 ms / 5,000 ms | 
| コード長 | 1,836 bytes | 
| コンパイル時間 | 619 ms | 
| コンパイル使用メモリ | 65,068 KB | 
| 実行使用メモリ | 74,240 KB | 
| 最終ジャッジ日時 | 2024-12-23 21:53:19 | 
| 合計ジャッジ時間 | 3,896 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 23 | 
ソースコード
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <utility>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define each(e,c) for(auto&e:c)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<(DUMP(),__VA_ARGS__).str()<<" ["<<__LINE__<<"]"<<endl)
struct DUMP:ostringstream{template<class T>DUMP &operator,(const T&t){if(this->tellp())*this<<", ";*this<<t;return *this;}};
#else
#define dump(...)
#endif
template<class T> ostream& operator<<(ostream& os, vector<T> const& v){
    rep(i,v.size()) os << v[i] << (i+1==v.size()?"":" ");
    return os;
}
int N;
int A[100010];
int dp1[3010][3010];
int dp2[3010][3010];
int rec1(int,int);
int rec2(int,int);
int rec1(int l, int r){
    int & res = dp1[l][r];
    if(res!=-1) return res;
    if(l==r) return res = 1;
    if(A[l] < A[r]) return res = max(rec1(l,r-1), rec2(l+1,r)+1);
    return res = rec1(l,r-1);
}
int rec2(int l, int r){
    int & res = dp2[l][r];
    if(res!=-1) return res;
    if(l==r) return res = 1;
    if(A[r] < A[l]) return res = max(rec2(l+1,r), rec1(l,r-1)+1);
    return res = rec2(l+1,r);
}
int main(){
    while(cin>>N && N){
        rep(i,N) cin >> A[i];
        rep(i,N)rep(j,N) dp1[i][j] = dp2[i][j] = -1;
        int ans = 1;
        rep(i,N){
            ans = max(ans, rec1(i,N-1));
            ans = max(ans, rec2(0,i));
        }
        cout << ans << endl;
    }
}
            
            
            
        
            
tubo28