結果

問題 No.1827 最長部分スーパーリッチ門松列列
ユーザー 👑 NachiaNachia
提出日時 2022-01-28 21:29:05
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 978 bytes
コンパイル時間 602 ms
コンパイル使用メモリ 77,056 KB
実行使用メモリ 7,080 KB
最終ジャッジ日時 2023-08-28 19:10:33
合計ジャッジ時間 3,327 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 5 ms
4,376 KB
testcase_04 AC 17 ms
4,380 KB
testcase_05 AC 17 ms
4,380 KB
testcase_06 AC 17 ms
4,376 KB
testcase_07 AC 49 ms
6,964 KB
testcase_08 AC 48 ms
7,068 KB
testcase_09 AC 48 ms
7,032 KB
testcase_10 AC 48 ms
6,948 KB
testcase_11 AC 48 ms
6,964 KB
testcase_12 AC 48 ms
7,032 KB
testcase_13 AC 47 ms
7,080 KB
testcase_14 AC 46 ms
6,956 KB
testcase_15 AC 47 ms
6,940 KB
testcase_16 AC 47 ms
6,952 KB
testcase_17 AC 54 ms
6,992 KB
testcase_18 AC 54 ms
6,996 KB
testcase_19 AC 52 ms
6,996 KB
testcase_20 AC 52 ms
6,936 KB
testcase_21 AC 52 ms
6,952 KB
testcase_22 AC 50 ms
6,936 KB
testcase_23 AC 49 ms
6,952 KB
testcase_24 AC 50 ms
6,964 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
using i32 = int;
using u32 = unsigned int;
#define rep(i,n) for(int i=0; i<(n); i++)


void testcase(){
    int N; cin >> N;
    vector<int> iP(N);
    rep(i,N){ int p; cin >> p; p--; iP[p] = i; }

    vector<int> flag(N, 0);
    int nowans = 1;
    int ans = 1;
    rep(i,N){
        int p = iP[i];
        if(p != 0) if(flag[p] != flag[p-1]) nowans--;
        if(p != N-1) if(flag[p] != flag[p+1]) nowans--;
        flag[p] ^= 1;
        if(p != 0) if(flag[p] != flag[p-1]) nowans++;
        if(p != N-1) if(flag[p] != flag[p+1]) nowans++;
        ans = max(ans, nowans);
    }
    cout << ans << "\n";
}


int main() {
    int T; cin >> T;
    while(T--) testcase();
    return 0;
}



struct ios_do_not_sync{
    ios_do_not_sync(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
    }
} ios_do_not_sync_instance;
0