結果

問題 No.1827 最長部分スーパーリッチ門松列列
ユーザー ぷらぷら
提出日時 2022-01-28 22:48:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 869 bytes
コンパイル時間 2,452 ms
コンパイル使用メモリ 200,688 KB
実行使用メモリ 9,132 KB
最終ジャッジ日時 2023-08-28 21:21:02
合計ジャッジ時間 6,996 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,384 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 169 ms
8,800 KB
testcase_08 AC 144 ms
8,856 KB
testcase_09 AC 144 ms
8,772 KB
testcase_10 AC 145 ms
8,864 KB
testcase_11 AC 145 ms
8,916 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 143 ms
8,852 KB
testcase_15 AC 144 ms
8,808 KB
testcase_16 AC 145 ms
8,924 KB
testcase_17 AC 168 ms
8,828 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 149 ms
8,796 KB
testcase_22 AC 147 ms
8,844 KB
testcase_23 AC 147 ms
8,828 KB
testcase_24 AC 146 ms
8,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    int T;
    cin >> T;
    while (T--) {
        int N;
        cin >> N;
        vector<int>P(N),Q(N+1);
        for(int i = 0; i < N; i++) {
            cin >> P[i];
            Q[P[i]] = i+1;
        }
        vector<int>res(N+2);
        int ans = 1,now = 1;
        for(int i = 1; i <= N; i++) {
            res[Q[i]] = 1;
            if(res[Q[i]-1] == 0 || res[Q[i]+1] == 0) {
                if(res[Q[i]-1] == 1 || res[Q[i]+1] == 1) {
                    continue;
                }
                if(Q[i] == 1 || Q[i] == N) {
                    now++;
                }
                else {
                    now += 2;
                }
                ans = max(ans,now);
            }
            else {
                now -= 2;
            }
        }
        cout << ans << endl;
    }
}
0