結果

問題 No.1188 レベルX門松列
ユーザー ktr216ktr216
提出日時 2020-08-22 14:29:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,470 bytes
コンパイル時間 1,758 ms
コンパイル使用メモリ 169,124 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-23 08:49:23
合計ジャッジ時間 4,188 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 89 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 WA -
testcase_07 AC 65 ms
6,944 KB
testcase_08 AC 84 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 3 ms
6,940 KB
testcase_11 AC 10 ms
6,944 KB
testcase_12 WA -
testcase_13 AC 12 ms
6,944 KB
testcase_14 AC 99 ms
6,944 KB
testcase_15 AC 192 ms
6,940 KB
testcase_16 AC 3 ms
6,940 KB
testcase_17 AC 152 ms
6,944 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 132 ms
6,940 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 2 ms
6,944 KB
testcase_23 AC 2 ms
6,944 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 = upper_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 = upper_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 = upper_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 = upper_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