結果

問題 No.1188 レベルX門松列
ユーザー outlineoutline
提出日時 2021-01-01 12:47:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 2,338 bytes
コンパイル時間 1,538 ms
コンパイル使用メモリ 136,316 KB
実行使用メモリ 6,912 KB
最終ジャッジ日時 2024-04-19 09:01:23
合計ジャッジ時間 2,737 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
6,912 KB
testcase_01 AC 40 ms
6,144 KB
testcase_02 AC 37 ms
5,888 KB
testcase_03 AC 45 ms
6,784 KB
testcase_04 AC 49 ms
6,784 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 20 ms
6,912 KB
testcase_07 AC 47 ms
6,784 KB
testcase_08 AC 43 ms
6,912 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 5 ms
5,376 KB
testcase_12 AC 4 ms
5,376 KB
testcase_13 AC 5 ms
5,376 KB
testcase_14 AC 28 ms
5,504 KB
testcase_15 AC 46 ms
6,784 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 36 ms
6,016 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 37 ms
5,888 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
// constexpr int mod = 1000000007;
constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; ++i)  cin >> A[i];

    vector<int> LIS(N), LIS2(N), LDS(N), LDS2(N);
    vector<int> dp(N, INF), dp2(N, INF), dp3(N, INF), dp4(N, INF);
    for(int i = 0; i < N; ++i){
        *lower_bound(begin(dp), end(dp), A[i]) = A[i];
        LIS[i] = lower_bound(begin(dp), end(dp), INF) - begin(dp);
        *lower_bound(begin(dp3), end(dp3), -A[i]) = -A[i];
        LDS[i] = lower_bound(begin(dp3), end(dp3), INF) - begin(dp3);
    }
    for(int i = N - 1; i >= 0; --i){
        *lower_bound(begin(dp2), end(dp2), A[i]) = A[i];
        LIS2[i] = lower_bound(begin(dp2), end(dp2), INF) - begin(dp2);
        *lower_bound(begin(dp4), end(dp4), -A[i]) = -A[i];
        LDS2[i] = lower_bound(begin(dp4), end(dp4), INF) - begin(dp4);
    }

    // cout << "LIS\nleft\n";
    // for(int i = 0; i < N; ++i)  cout << LIS[i] << ' ';
    // cout << "\nright\n";
    // for(int i = 0; i < N; ++i)  cout << LIS2[i] << ' ';
    // cout << "\nLDS\nleft\n";
    // for(int i = 0; i < N; ++i)  cout << LDS[i] << ' ';
    // cout << "\nright\n";
    // for(int i = 0; i < N; ++i)  cout << LDS2[i] << ' ';
    // cout << '\n';

    int ans = 0;
    for(int i = 0; i < N; ++i){
        chmax(ans, max(min(LIS[i], LIS2[i]), min(LDS[i], LDS2[i])) - 1);
    }
    cout << ans << endl;

    return 0;
}
0