結果

問題 No.1827 最長部分スーパーリッチ門松列列
ユーザー 👑 NachiaNachia
提出日時 2022-01-28 21:27:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,005 bytes
コンパイル時間 648 ms
コンパイル使用メモリ 76,944 KB
実行使用メモリ 7,168 KB
最終ジャッジ日時 2023-08-28 19:07:23
合計ジャッジ時間 3,062 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 47 ms
7,048 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 48 ms
7,032 KB
testcase_23 WA -
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

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+2, 0);
    int nowans = 1;
    int ans = 1;
    rep(i,N){
        int p = iP[i];
        if(flag[p] != flag[p+1]) nowans--;
        if(flag[p+2] != flag[p+1]) nowans--;
        flag[p+1] ^= 1;
        if(flag[p] != flag[p+1]) nowans++;
        if(flag[p+2] != flag[p+1]) nowans++;
        int newans2 = nowans;
        if(flag[N] == 1) newans2--;
        ans = max(ans, newans2);
    }
    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