結果

問題 No.1709 Indistinguishable by MEX
ユーザー wolgnikwolgnik
提出日時 2021-10-15 22:14:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 136 ms / 2,000 ms
コード長 1,189 bytes
コンパイル時間 928 ms
コンパイル使用メモリ 81,812 KB
実行使用メモリ 123,428 KB
最終ジャッジ日時 2023-10-17 20:23:43
合計ジャッジ時間 4,258 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,544 KB
testcase_01 AC 38 ms
53,544 KB
testcase_02 AC 38 ms
53,544 KB
testcase_03 AC 38 ms
53,544 KB
testcase_04 AC 38 ms
53,544 KB
testcase_05 AC 38 ms
53,544 KB
testcase_06 AC 38 ms
53,544 KB
testcase_07 AC 38 ms
53,544 KB
testcase_08 AC 118 ms
123,428 KB
testcase_09 AC 105 ms
115,424 KB
testcase_10 AC 100 ms
110,440 KB
testcase_11 AC 91 ms
102,688 KB
testcase_12 AC 90 ms
100,812 KB
testcase_13 AC 119 ms
122,712 KB
testcase_14 AC 114 ms
117,028 KB
testcase_15 AC 117 ms
120,016 KB
testcase_16 AC 133 ms
109,244 KB
testcase_17 AC 123 ms
117,404 KB
testcase_18 AC 128 ms
123,316 KB
testcase_19 AC 129 ms
123,092 KB
testcase_20 AC 128 ms
123,316 KB
testcase_21 AC 136 ms
109,632 KB
testcase_22 AC 133 ms
109,608 KB
testcase_23 AC 135 ms
109,664 KB
testcase_24 AC 135 ms
109,664 KB
testcase_25 AC 133 ms
109,552 KB
testcase_26 AC 37 ms
53,544 KB
testcase_27 AC 91 ms
104,668 KB
testcase_28 AC 86 ms
100,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
mod = 998244353
reva = [0] * N
for i in range(N): reva[a[i]] = i

l = reva[: ]
r = reva[: ]
for i in range(N - 1):
  l[i + 1] = min(l[i], reva[i + 1])
  r[i + 1] = max(r[i], reva[i + 1])
  
#print(l, r, reva)

class Factorial:
  def __init__(self, n, mod):
    self.mod = mod
    self.f = [1]
    for i in range(1, n + 1): self.f.append(self.f[-1] * i % mod)
    self.i = [pow(self.f[-1], mod - 2, mod)]
    for i in range(1, n + 1)[: : -1]: self.i.append(self.i[-1] * i % mod)
    self.i.reverse()
  def factorial(self, i): return self.f[i]
  def ifactorial(self, i): return self.i[i]
  def combi(self, n, k): return self.f[n] * self.i[n - k] % self.mod * self.i[k] % self.mod
  def permi(self, n, k): return self.f[n] * self.i[n - k] % self.mod

f = Factorial(N, mod)
res = 1
dsm = 0
ll = l[0]
rr = r[0]
for i in range(1, N):
  d = max(0, ll - l[i] - 1) + max(0, r[i] - rr - 1)
  if d == 0 and ll == l[i] and rr == r[i]:
    res *= dsm
    res %= mod
    dsm -= 1
  else: dsm += d
  ll = l[i]
  rr = r[i]
  #print(res, d, ll, rr, dsm)
if dsm > 0:
  res *= f.factorial(dsm)
  res %= mod
print(res)
0