結果

問題 No.1709 Indistinguishable by MEX
ユーザー chineristACchineristAC
提出日時 2021-05-28 18:53:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 1,905 bytes
コンパイル時間 8,653 ms
コンパイル使用メモリ 287,728 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 19:44:46
合計ジャッジ時間 10,395 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 26 ms
4,348 KB
testcase_09 AC 21 ms
4,348 KB
testcase_10 AC 20 ms
4,348 KB
testcase_11 AC 16 ms
4,348 KB
testcase_12 AC 14 ms
4,348 KB
testcase_13 AC 22 ms
4,348 KB
testcase_14 AC 20 ms
4,348 KB
testcase_15 AC 22 ms
4,348 KB
testcase_16 AC 28 ms
4,348 KB
testcase_17 AC 26 ms
4,348 KB
testcase_18 AC 32 ms
4,348 KB
testcase_19 AC 32 ms
4,348 KB
testcase_20 AC 32 ms
4,348 KB
testcase_21 AC 29 ms
4,348 KB
testcase_22 AC 29 ms
4,348 KB
testcase_23 AC 28 ms
4,348 KB
testcase_24 AC 27 ms
4,348 KB
testcase_25 AC 27 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 15 ms
4,348 KB
testcase_28 AC 14 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <random>
#include <stdio.h>
#include <fstream>
#include <functional>
#include <atcoder/all>
#include "testlib.h"
#include <cassert>
using namespace std;
using namespace atcoder;

#define rep(i,n,c) for (int i=0;i<n;i+=c)
#define append push_back
#define all(x) (x).begin(), (x).end()

template<class T>
using vec = vector<T>;
template<class T>
using vvec = vec<vec<T>>;
template<class T>
using vvvec = vec<vvec<T>>;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;


template<class T>
bool chmin(T &a, T b){
  if (a>b){
    a = b;
    return true;
  }
  return false;
}

template<class T>
bool chmax(T &a, T b){
  if (a<b){
    a = b;
    return true;
  }
  return false;
}

template<class T>
T sum(vec<T> x){
  T res=0;
  for (auto e:x){
    res += e;
  }
  return res;
}

template<class T>
void printv(vec<T> x){
  for (auto e:x){
    cout<<e<<" ";
  }
  cout<<"\n";
}


const ll INF = 1e17;

const int MIN_N = 1;
const int MAX_N = 200000;
const int MIN_M = 1;
const int MAX_M = 200000;


using mint = modint998244353;
const mint i2 = ((mint)(2)).inv();

int main(int argc, char* argv[]){
  registerValidation(argc,argv);
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);

  int N,p;
  N = inf.readInt(MIN_N,MAX_N,"N");
  inf.readEoln();
  vector<int> pos(N,-1);
  for (int i=0;i<N;i++){
    p = inf.readInt(0,N-1);
    assert (pos[p]==-1);
    pos[p] = i;

    if (i!=N-1){
      inf.readSpace();
    }
    else{
      inf.readEoln();
    }
  }
  inf.readEof();

  int L = pos[0];
  int R = pos[0];
  mint res=1;
  for (int i=1;i<N;i++){
    if (L<=pos[i] and pos[i]<=R){
      res *= (mint)(R-L+1-i);
    }
    else{
      chmin(L,pos[i]);
      chmax(R,pos[i]);
    }
  }

  cout<<res.val()<<endl;

}
0