結果

問題 No.1709 Indistinguishable by MEX
ユーザー umezo
提出日時 2021-10-16 00:03:50
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 521 bytes
コンパイル時間 4,446 ms
コンパイル使用メモリ 193,716 KB
最終ジャッジ日時 2025-01-25 01:24:30
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
 
#include<bits/stdc++.h>
using namespace std;

const ll MOD=998244353;

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  int n;
  cin>>n;
  vector<ll> P(n),A(n);
  rep(i,n){
    cin>>P[i];
    A[P[i]]=i;
  }
  
  int m=A[0];
  int l=m,r=m;
  ll ans=1;
  for(int i=1;i<n;i++){
    if(A[i]<l) l=A[i];
    else if(A[i]>r) r=A[i];
    else ans=ans*(r-l-i+1)%MOD;
  }
  cout<<ans<<endl;

  return 0;
}
0