結果

問題 No.1188 レベルX門松列
ユーザー rogi52rogi52
提出日時 2022-10-04 01:31:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 40 ms / 2,000 ms
コード長 1,032 bytes
コンパイル時間 3,720 ms
コンパイル使用メモリ 203,732 KB
実行使用メモリ 5,476 KB
最終ジャッジ日時 2023-08-27 22:45:18
合計ジャッジ時間 3,682 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
5,476 KB
testcase_01 AC 32 ms
4,972 KB
testcase_02 AC 29 ms
4,988 KB
testcase_03 AC 39 ms
5,428 KB
testcase_04 AC 33 ms
5,416 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 17 ms
5,344 KB
testcase_07 AC 33 ms
5,368 KB
testcase_08 AC 33 ms
5,472 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 4 ms
4,376 KB
testcase_12 AC 4 ms
4,380 KB
testcase_13 AC 4 ms
4,376 KB
testcase_14 AC 25 ms
4,416 KB
testcase_15 AC 40 ms
5,320 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 31 ms
4,944 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 30 ms
4,852 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 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(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int N; cin >> N;
    vector<int> A(N);
    rep(i,N) cin >> A[i];

    auto f = [N](vector<int> A) {
        auto LIS = [N](vector<int> A) {
            int INF = numeric_limits<int>::max();
            vector<int> dp(N, INF), rank(N);
            rep(i,N) {
                int p = lower_bound(dp.begin(), dp.end(), A[i]) - dp.begin();
                dp[p] = A[i];
                rank[i] = p + 1;
            }
            return rank;
        };

        vector<int> L = LIS(A);
        reverse(A.begin(), A.end());
        vector<int> R = LIS(A);
        reverse(A.begin(), A.end());
        reverse(R.begin(), R.end());
        int ans = 0;
        rep(i,N) ans = max(ans, min(L[i], R[i]) - 1);
        return ans;
    };

    int ans = 0;
    rep(_,2) {
        ans = max(ans, f(A));
        rep(i,N) A[i] *= -1;
    }
    cout << ans << endl;
}
0