結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 144 ms
8,800 KB
testcase_08 AC 144 ms
8,868 KB
testcase_09 AC 147 ms
8,776 KB
testcase_10 AC 146 ms
8,840 KB
testcase_11 AC 144 ms
8,944 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 146 ms
8,940 KB
testcase_23 AC 145 ms
8,920 KB
testcase_24 AC 146 ms
8,868 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 {
                if(Q[i] == 1 || Q[i] == N) {
                    now--;
                }
                else {
                    now -= 2;
                }
            }
        }
        cout << ans << endl;
    }
}
0