結果

問題 No.1188 レベルX門松列
ユーザー pes_magicpes_magic
提出日時 2020-08-22 13:57:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 899 bytes
コンパイル時間 706 ms
コンパイル使用メモリ 74,316 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-23 08:23:14
合計ジャッジ時間 2,207 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
6,812 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 43 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 20 ms
6,944 KB
testcase_07 AC 43 ms
6,940 KB
testcase_08 AC 43 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 66 ms
6,940 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 2 ms
6,940 KB
testcase_19 WA -
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> LIS(const vector<int>& v){
    vector<int> res(v.size(), 1);
    vector<int> a(v.size(), v[0]);
    auto end = a.begin();
    ++end;
    int size = 0;
    for(int i=1;i<v.size();i++){
        auto l = lower_bound(a.begin(), end, v[i]);
        if(l == end) ++end;
        *l = v[i];
        res[i] = distance(a.begin(), l) + 1;
    }
    return res;
}

int solve(vector<int>& a){
    auto f = LIS(a);
    reverse(a.begin(), a.end());
    auto g = LIS(a);
    int res = 0;
    for(int i=0;i<a.size();i++){
        res = max(res, (f[i]+g[a.size()-i-1])/2-1);
    }
    return res;
}

int main(){
    int N;
    while(cin >> N){
        vector<int> A(N), B(N);
        for(int i=0;i<N;i++){
            cin >> A[i];
            B[i] = -A[i];
        }
        cout << max(solve(A), solve(B)) << endl;
    }
}
0