結果

問題 No.1188 レベルX門松列
ユーザー boutarouboutarou
提出日時 2020-08-24 22:48:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 83 ms / 2,000 ms
コード長 1,357 bytes
コンパイル時間 796 ms
コンパイル使用メモリ 74,416 KB
実行使用メモリ 8,192 KB
最終ジャッジ日時 2024-04-24 03:58:59
合計ジャッジ時間 2,189 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
8,064 KB
testcase_01 AC 60 ms
7,296 KB
testcase_02 AC 54 ms
6,912 KB
testcase_03 AC 76 ms
8,192 KB
testcase_04 AC 68 ms
8,064 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 29 ms
8,064 KB
testcase_07 AC 63 ms
8,064 KB
testcase_08 AC 64 ms
8,064 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 7 ms
5,376 KB
testcase_12 AC 6 ms
5,376 KB
testcase_13 AC 7 ms
5,376 KB
testcase_14 AC 47 ms
6,144 KB
testcase_15 AC 83 ms
7,808 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 65 ms
6,912 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 60 ms
6,656 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>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
using ll = long long;

constexpr ll INF = 2e9;

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    vector<ll> dp(n, INF);
    vector<ll> front_up(n), back_up(n);
    vector<ll> front_down(n), back_down(n);
    rep(i, n) {
        front_up[i] = lower_bound(dp.begin(), dp.end(), a[i]) - dp.begin() + 1;
        *lower_bound(dp.begin(), dp.end(), a[i]) = a[i];
    }
    rep(i, n) dp[i] = INF;
    for (ll i = n - 1; i >= 0; i--) {
        back_up[i] = lower_bound(dp.begin(), dp.end(), a[i]) - dp.begin() + 1;
        *lower_bound(dp.begin(), dp.end(), a[i]) = a[i];
    }
    rep(i, n) dp[i] = INF;
    rep(i, n) a[i] *= -1;
    rep(i, n) {
        front_down[i] = lower_bound(dp.begin(), dp.end(), a[i]) - dp.begin() + 1;
        *lower_bound(dp.begin(), dp.end(), a[i]) = a[i];
    }
    rep(i, n) dp[i] = INF;
    for (ll i = n - 1; i >= 0; i--) {
        back_down[i] = lower_bound(dp.begin(), dp.end(), a[i]) - dp.begin() + 1;
        *lower_bound(dp.begin(), dp.end(), a[i]) = a[i];
    }
    ll ans = 0;
    rep(i, n) {
        ans = max(ans, min(front_up[i] - 1, back_up[i] - 1));
        ans = max(ans, min(front_down[i] - 1, back_down[i] - 1));
    }
    cout << ans << endl;
    return 0;
}
0