結果

問題 No.1709 Indistinguishable by MEX
ユーザー horitaka1999horitaka1999
提出日時 2021-11-07 00:34:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 148 ms / 2,000 ms
コード長 471 bytes
コンパイル時間 387 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 124,672 KB
最終ジャッジ日時 2024-11-08 00:11:24
合計ジャッジ時間 5,398 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
N = int(input())                    
P = list(map(int,input().split()))
dic = defaultdict(int)
for i in range(N):
    dic[P[i]] = i
l = 0
r = 0
ans = 1
mod = 998244353
for x in range(N):
    if x == 0:
        l = dic[x]
        r = dic[x]
    else:
        index = dic[x]
        if l < index < r:
            ans *= (r-l+1-x)
            ans %= mod
        else:
            l = min(index,l)
            r = max(index,r)
print(ans)

0