結果

問題 No.1188 レベルX門松列
ユーザー ktr216ktr216
提出日時 2020-08-22 14:43:10
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 176 ms / 2,000 ms
コード長 2,470 bytes
コンパイル時間 2,121 ms
コンパイル使用メモリ 169,948 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-23 09:01:53
合計ジャッジ時間 4,001 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
6,816 KB
testcase_01 AC 135 ms
6,940 KB
testcase_02 AC 114 ms
6,940 KB
testcase_03 AC 170 ms
6,940 KB
testcase_04 AC 84 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 30 ms
6,944 KB
testcase_07 AC 64 ms
6,940 KB
testcase_08 AC 83 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 9 ms
6,944 KB
testcase_12 AC 10 ms
6,940 KB
testcase_13 AC 10 ms
6,940 KB
testcase_14 AC 91 ms
6,940 KB
testcase_15 AC 176 ms
6,940 KB
testcase_16 AC 3 ms
6,940 KB
testcase_17 AC 136 ms
6,940 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 117 ms
6,944 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 1 ms
6,940 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    int ok = 0, ng = (N - 1) / 2 + 1;
    while (ok + 1 < ng) {
        int mi = (ok + ng) / 2;
        int i = 1;
        vector<int> v = {A[0]};
        bool f = false;
        while (i < N) {
            int j = lower_bound(v.begin(), v.end(), A[i]) - v.begin();
            if (j == v.size()) {
                v.push_back(A[i]);
                if (v.size() == mi + 1) {
                    f = true;
                    break;
                }
            } else {
                v[j] = min(v[j], A[i]);
            }
            i++;
        }
        if (f) {
            v = {-A[i]};
            i++;
            f = false;
            while (i < N) {
                int j = lower_bound(v.begin(), v.end(), -A[i]) - v.begin();
                if (j == v.size()) {
                    v.push_back(-A[i]);
                    if (v.size() == mi + 1) {
                        f = true;
                        break;
                    }
                } else {
                    v[j] = min(v[j], -A[i]);
                }
                i++;
            }
            if (f) {
                ok = mi;
                continue;
            }
        }
        i = 1;
        v = {-A[0]};
        f = false;
        while (i < N) {
            int j = lower_bound(v.begin(), v.end(), -A[i]) - v.begin();
            if (j == v.size()) {
                v.push_back(-A[i]);
                if (v.size() == mi + 1) {
                    f = true;
                    break;
                }
            } else {
                v[j] = min(v[j], -A[i]);
            }
            i++;
        }
        if (f) {
            v = {A[i]};
            i++;
            f = false;
            while (i < N) {
                int j = lower_bound(v.begin(), v.end(), A[i]) - v.begin();
                if (j == v.size()) {
                    v.push_back(A[i]);
                    if (v.size() == mi + 1) {
                        f = true;
                        break;
                    }
                } else {
                    v[j] = min(v[j], A[i]);
                }
                i++;
            }
            if (f) {
                ok = mi;
                continue;
            }
        }
        ng = mi;
    }
    cout << ok << "\n";
}
0