結果

問題 No.1709 Indistinguishable by MEX
ユーザー hiro71687k
提出日時 2023-04-02 19:57:49
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 776 bytes
コンパイル時間 3,937 ms
コンパイル使用メモリ 250,732 KB
最終ジャッジ日時 2025-02-11 22:25:24
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;
using ld=long double;
ld pie=3.141592653589793;
ll inf=1444999994999999;
ll mod=998244353;
int main(){
    ll n;
    cin >> n;
    vector<ll>p(n);
    ll left=inf,right=0;
    vector<ll>memo(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> p[i];
        memo[p[i]]=i;
        if (p[i]==0||p[i]==1)
        {
            left=min(left,i);
            right=max(right,i);
        }
    }
    ll ans=1;
    for (ll i = 2; i < n; i++)
    {
        if (left<=memo[i]&&memo[i]<=right)
        {
            ans*=(right-left-i+1);
            ans%=mod;
        }
        left=min(left,memo[i]);
        right=max(memo[i],right);
    }
    cout << ans << endl;
}
0