結果

問題 No.1709 Indistinguishable by MEX
ユーザー 57tggx57tggx
提出日時 2021-10-15 21:45:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 1,928 bytes
コンパイル時間 2,102 ms
コンパイル使用メモリ 73,228 KB
実行使用メモリ 4,896 KB
最終ジャッジ日時 2023-10-17 20:11:40
合計ジャッジ時間 2,808 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 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 57 ms
4,632 KB
testcase_09 AC 44 ms
4,368 KB
testcase_10 AC 42 ms
4,368 KB
testcase_11 AC 33 ms
4,348 KB
testcase_12 AC 33 ms
4,348 KB
testcase_13 AC 48 ms
4,368 KB
testcase_14 AC 44 ms
4,368 KB
testcase_15 AC 46 ms
4,368 KB
testcase_16 AC 62 ms
4,896 KB
testcase_17 AC 57 ms
4,632 KB
testcase_18 AC 69 ms
4,896 KB
testcase_19 AC 71 ms
4,896 KB
testcase_20 AC 71 ms
4,896 KB
testcase_21 AC 64 ms
4,896 KB
testcase_22 AC 64 ms
4,896 KB
testcase_23 AC 62 ms
4,896 KB
testcase_24 AC 62 ms
4,896 KB
testcase_25 AC 62 ms
4,896 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 33 ms
4,348 KB
testcase_28 AC 31 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cstdint>

template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

public:
  u64 a;

  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};

int main(){
	std::size_t n;
	std::cin >> n;
	std::vector<std::size_t> pos(n);
	for(std::size_t i = 0; i < n; ++i){
		std::size_t p;
		std::cin >> p;
		pos[p] = i;
	}
	modint<998244353> ans = 1;
	std::size_t l = pos[0], r = pos[0];
	std::size_t tmp = 1;
	for(std::size_t i = 1; i < n; ++i){
		if(pos[i] > r){
			tmp += pos[i] - r;
			r = pos[i];
		}else if(pos[i] < l){
			tmp += l - pos[i];
			l = pos[i];
		}else{
			ans *= tmp - 1;
		}
		--tmp;
		// std::cout << i << ": " << l << " " << r << " (" << tmp << ")" << std::endl;
	}
	std::cout << ans.a << std::endl;
}
0