結果

問題 No.127 門松もどき
ユーザー ctyl_0ctyl_0
提出日時 2015-12-27 01:46:46
言語 C++11
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,728 bytes
コンパイル時間 819 ms
コンパイル使用メモリ 90,560 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-19 07:19:14
合計ジャッジ時間 1,799 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 15 WA * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define var auto
#define mod 1000000007
#define inf 2147483647
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;

template <typename T>
inline void output(T a, int p) {
    if(p){
        cout << fixed << setprecision(p)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}
// end of template

int main() {
    cin.tie(0);
    //ios::sync_with_stdio(0);
    // source code
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N){
        cin >> A[i];
    }
    
    vector<vector<int>> dpl(2, vector<int>(N, 1)), dpr(2, vector<int>(N, 1));
    
    repd(i, 1, N){
        repd(j, 0, N - i){
            dpl[0][j] = dpl[1][j];
            if (A[j] < A[i + j]) {
                dpl[0][j] = max(dpl[0][j], dpr[1][j + 1] + 1);
            }
            dpr[0][j] = dpr[1][j + 1];
            if (A[j] > A[i + j]) {
                dpr[0][j] = max(dpl[1][j] + 1, dpr[0][j]);
            }
        }
        dpl[1] = dpl[0];
        dpr[1] = dpr[0];
//        cout << "phase " << i << endl;
//        cout << "l: ";
//        rep(j, N - i){
//            if(j) cout << " ";
//            cout << dpl[1][j];
//        }
//        cout << endl;
//        cout << "r: ";
//        rep(j, N - i){
//            if(j) cout << " ";
//            cout << dpr[1][j];
//        }
//        cout << endl;
    }
    
    output(max(dpl[0][0], dpr[0][0]), 0);
    
    return 0;
}
0