結果

問題 No.1709 Indistinguishable by MEX
ユーザー ぷらぷら
提出日時 2021-10-15 21:43:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 845 bytes
コンパイル時間 2,041 ms
コンパイル使用メモリ 204,892 KB
実行使用メモリ 6,484 KB
最終ジャッジ日時 2023-10-17 20:10:43
合計ジャッジ時間 4,214 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 55 ms
5,956 KB
testcase_09 AC 44 ms
5,428 KB
testcase_10 AC 42 ms
5,428 KB
testcase_11 AC 33 ms
4,900 KB
testcase_12 AC 34 ms
4,900 KB
testcase_13 AC 48 ms
5,692 KB
testcase_14 AC 45 ms
5,428 KB
testcase_15 AC 48 ms
5,692 KB
testcase_16 AC 63 ms
6,220 KB
testcase_17 AC 58 ms
6,220 KB
testcase_18 AC 70 ms
6,484 KB
testcase_19 AC 68 ms
6,484 KB
testcase_20 AC 68 ms
6,484 KB
testcase_21 AC 65 ms
6,484 KB
testcase_22 AC 65 ms
6,484 KB
testcase_23 AC 65 ms
6,484 KB
testcase_24 AC 65 ms
6,484 KB
testcase_25 AC 64 ms
6,484 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 35 ms
5,164 KB
testcase_28 AC 32 ms
4,900 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

constexpr int mod = 998244353;

int main() {
    int N;
    cin >> N;
    vector<int>P(N),Q(N);
    for(int i = 0; i < N; i++) {
        cin >> P[i];
        Q[P[i]] = i;
    }
    vector<long long>fac(N);
    fac[0] = 1;
    for(int i = 1; i < N; i++) {
        fac[i] = fac[i-1]*i%mod;
    }
    long long ans = 1;
    int l = 0,r = 0,cnt = 0;
    for(int i = 0; i < N; i++) {
        if(i == 0) {
            cnt++;
            l = Q[i];
            r = Q[i];
        }
        else {
            if(l <= Q[i] && Q[i] <= r) {
                ans *= r-l-i+1;
                ans %= mod;
                continue;
            }
            if(Q[i] < l) {
                l = Q[i];
            }
            else {
                r = Q[i];
            }
        }
    }
    cout << ans << endl;
}
0