結果

問題 No.1827 最長部分スーパーリッチ門松列列
ユーザー suisensuisen
提出日時 2022-01-29 00:35:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 1,122 bytes
コンパイル時間 601 ms
コンパイル使用メモリ 74,908 KB
実行使用メモリ 9,084 KB
最終ジャッジ日時 2023-08-28 23:37:16
合計ジャッジ時間 4,331 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 4 ms
4,380 KB
testcase_04 AC 16 ms
4,380 KB
testcase_05 AC 16 ms
4,380 KB
testcase_06 AC 17 ms
4,380 KB
testcase_07 AC 51 ms
8,944 KB
testcase_08 AC 51 ms
8,840 KB
testcase_09 AC 51 ms
8,836 KB
testcase_10 AC 51 ms
8,896 KB
testcase_11 AC 51 ms
8,792 KB
testcase_12 AC 51 ms
8,824 KB
testcase_13 AC 52 ms
8,832 KB
testcase_14 AC 51 ms
8,856 KB
testcase_15 AC 51 ms
8,832 KB
testcase_16 AC 51 ms
8,804 KB
testcase_17 AC 58 ms
9,008 KB
testcase_18 AC 58 ms
8,808 KB
testcase_19 AC 51 ms
8,896 KB
testcase_20 AC 51 ms
8,808 KB
testcase_21 AC 51 ms
9,084 KB
testcase_22 AC 52 ms
8,848 KB
testcase_23 AC 52 ms
8,928 KB
testcase_24 AC 52 ms
8,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int t;
    std::cin >> t;
    while (t --> 0) {
        int n;
        std::cin >> n;
        std::vector<int> p(n);
        for (auto &e : p) {
            std::cin >> e;
            --e;
        }
        std::vector<int> q(n);
        for (int i = 0; i < n; ++i) {
            q[p[i]] = i;
        }
        int block_num = 1;
        std::vector<int> x(n, 1);
        auto update = [&](int i, int v) {
            block_num -= i > 0     and x[i - 1] != x[i];
            block_num -= i + 1 < n and x[i + 1] != x[i];
            x[i] = v;
            block_num += i > 0     and x[i - 1] != x[i];
            block_num += i + 1 < n and x[i + 1] != x[i];
        };

        int ans = 0;
        for (int i : q) {
            update(i, -1);
            int len = block_num;
            len -= i > 0     and x[i - 1] == 1;
            len -= i + 1 < n and x[i + 1] == 1;
            ans = std::max(ans, len);
            update(i, 0);
        }
        std::cout << ans << '\n';
    }
    return 0;
}
0