結果

問題 No.1709 Indistinguishable by MEX
ユーザー puznekopuzneko
提出日時 2021-11-05 01:30:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 259 ms / 2,000 ms
コード長 1,038 bytes
コンパイル時間 191 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 116,500 KB
最終ジャッジ日時 2024-04-23 08:16:52
合計ジャッジ時間 4,590 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
52,352 KB
testcase_01 AC 36 ms
52,352 KB
testcase_02 AC 36 ms
52,352 KB
testcase_03 AC 33 ms
51,968 KB
testcase_04 AC 32 ms
52,096 KB
testcase_05 AC 32 ms
52,352 KB
testcase_06 AC 32 ms
52,352 KB
testcase_07 AC 32 ms
52,480 KB
testcase_08 AC 79 ms
102,272 KB
testcase_09 AC 74 ms
96,236 KB
testcase_10 AC 74 ms
92,996 KB
testcase_11 AC 65 ms
88,448 KB
testcase_12 AC 62 ms
86,208 KB
testcase_13 AC 91 ms
106,496 KB
testcase_14 AC 90 ms
103,224 KB
testcase_15 AC 90 ms
106,672 KB
testcase_16 AC 103 ms
115,940 KB
testcase_17 AC 97 ms
111,480 KB
testcase_18 AC 89 ms
112,448 KB
testcase_19 AC 90 ms
112,224 KB
testcase_20 AC 90 ms
112,172 KB
testcase_21 AC 102 ms
116,040 KB
testcase_22 AC 102 ms
116,500 KB
testcase_23 AC 256 ms
116,404 KB
testcase_24 AC 259 ms
116,348 KB
testcase_25 AC 257 ms
116,316 KB
testcase_26 AC 33 ms
53,276 KB
testcase_27 AC 165 ms
107,036 KB
testcase_28 AC 156 ms
103,628 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import stdin
n, *a = map(int, stdin.read().split())
p = 998244353
if n <= 2:
    print("{}".format(1))
    exit()

def powmod(n,pow,mod):
    val = 1
    while pow > 0:
        if pow & 1:
            val = (val * n) % mod
        pow = pow >> 1
        n = (n * n) % mod
    return val

kaijo = [1 for i in range(n)]
for i in range(1,n):
    kaijo[i] = kaijo[i-1] * i % p

ichi = [0 for i in range(n)]
for i in range(n):
    ichi[a[i]] = i

left = ichi[0]
right = ichi[1]
if left > right:
    left, right = right, left

anslist = [(right - left - 1,1)]
for i in range(2,n):
    if ichi[i] < left:
        anslist.append((left - ichi[i] - 1,i))
        left = ichi[i]
    elif ichi[i] > right:
        anslist.append((ichi[i] - right - 1,i))
        right = ichi[i]

last = 0
remained = 0
ans = 1
for range, ind in anslist:
    ans = ans * kaijo[remained] % p * powmod(kaijo[remained-(ind-last-1)],p-2,p) % p
    remained += range
    remained -= ind-last-1
    last = ind

ans = ans * kaijo[remained] % p
print("{}".format(ans))
0