結果

問題 No.1188 レベルX門松列
ユーザー minatominato
提出日時 2020-08-27 09:05:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 2,729 bytes
コンパイル時間 3,587 ms
コンパイル使用メモリ 252,300 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-27 03:27:00
合計ジャッジ時間 4,999 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
6,812 KB
testcase_01 AC 35 ms
6,944 KB
testcase_02 AC 31 ms
6,940 KB
testcase_03 AC 42 ms
6,944 KB
testcase_04 AC 36 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 27 ms
6,940 KB
testcase_07 AC 37 ms
6,940 KB
testcase_08 AC 34 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 4 ms
6,944 KB
testcase_12 AC 4 ms
6,940 KB
testcase_13 AC 5 ms
6,940 KB
testcase_14 AC 25 ms
6,940 KB
testcase_15 AC 44 ms
6,944 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 34 ms
6,944 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 31 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,940 KB
testcase_23 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2,avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln = '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) {if (a < b) {a = b; return true;} return false;}
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) {if (a > b) {a = b; return true;} return false;}
inline int topbit(int x) {return x == 0 ? -1 : 31-__builtin_clz(x);}
inline int topbit(long long x) {return x == 0 ? -1 : 63-__builtin_clzll(x);}
inline int botbit(int x) {return x == 0 ? 32 : __builtin_ctz(x);}
inline int botbit(long long x) {return x == 0 ? 64 : __builtin_ctzll(x);}
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
void print() {cout << "\n";}
template<class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    auto solve1=[](const vector<int> &A) {
        int N = A.size();
        vector<int> ret(N);
        vector<int> dp(N+1);
        dp[0] = MOD;
        rep(i,N) {
            int ng = 0;
            int ok = N;
            while (abs(ng-ok)>1) {
                int mid = (ng+ok)/2;
                if (dp[mid]<=A[i]) ok = mid;
                else ng = mid;
            }
            ret[i] = ok;
            dp[ok] = A[i];
        }
        return ret;
    };
    auto solve2=[](const vector<int> &A) {
        int N = A.size();
        vector<int> ret(N);
        vector<int> dp(N+1,1e9);
        dp[0] = 0;
        rep(i,N) {
            ret[i] = lower_bound(all(dp),A[i]) - dp.begin();
            dp[ret[i]] = A[i];
        }
        return ret;
    };

    int N; cin >> N;
    vector<int> A(N);
    rep(i,N) cin >> A[i];

    int ans = 0;

    auto B = solve1(A);
    reverse(all(A));
    auto Brev = solve1(A);
    reverse(all(Brev));
    rep(i,N) {
        chmax(ans,min(B[i],Brev[i])-1);
    }

    reverse(all(A));
    auto C = solve2(A);
    reverse(all(A));
    auto Crev = solve2(A);
    reverse(all(Crev));
    rep(i,N) {
        chmax(ans,min(C[i],Crev[i])-1);
    }

    cout << ans << ln;
}
0