結果

問題 No.1709 Indistinguishable by MEX
ユーザー trineutron
提出日時 2021-10-15 22:20:02
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 662 bytes
コンパイル時間 2,400 ms
コンパイル使用メモリ 247,880 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-17 17:38:23
合計ジャッジ時間 4,399 ms
ジャッジサーバーID
(参考情報)
judge3 / judge6
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/modint>

using namespace std;
using namespace atcoder;

using mint = modint998244353;

int main()
{
    int n;
    cin >> n;
    int l = n, r = -1;
    vector<int> p(n), idx(n);
    for (int i = 0; i < n; i++)
    {
        cin >> p.at(i);
        idx.at(p.at(i)) = i;
    }
    mint ans = 1;
    for (int i = 0; i < n; i++)
    {
        int v = r - l + 1 - i;
        if (idx.at(i) < l)
        {
            l = idx.at(i);
            v = 1;
        }
        if (idx.at(i) > r)
        {
            r = idx.at(i);
            v = 1;
        }
        ans *= v;
    }
    cout << ans.val() << endl;
    return 0;
}
0