AtCoder Regular Contest 178
D
Delete Range Mex
AtCoder
⌀ 2498
原题
← CE →
翻译中…

Problem Statement

翻译中…

You are given a positive integer $N$ and a sequence of $M$ non-negative integers $A = (A_{1}, A_{2}, \dots, A_{M})$.

翻译中…

Here, all elements of $A$ are distinct integers between $0$ and $N-1$, inclusive.

翻译中…

Find the number, modulo $998244353$, of permutations $P$ of $(0, 1, \dots, N-1)$ that satisfy the following condition.

翻译中…
  • After initializing a sequence $B = (B_{1}, B_{2}, \dots, B_{N})$ to $P$, it is possible to make $B = A$ by repeating the following operation some number of times:
  • Choose $l$ and $r$ such that $1 \leq l \leq r \leq |B|$, and if $\mathrm{mex}(\{B_{l}, B_{l+1}, \dots, B_{r}\})$ is contained in $B$, remove it from $B$.
翻译中…

What is $\mathrm{mex}(X)$? For a finite set $X$ of non-negative integers, $\mathrm{mex}(X)$ is defined as the smallest non-negative integer that is not in $X$.

翻译中…

Constraints

翻译中…
  • $1 \leq M \leq N \leq 500$
  • $0 \leq A_{i} < N$
  • All elements of $A$ are distinct.
  • All input values are integers.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

N M
A_{1} A_{2} \cdots A_{M}

翻译中…

Output

翻译中…

Print the answer.

翻译中…

样例

Input #1
4 2
1 3
Output #1
8
After initializing $B = (2, 1, 0, 3)$, it is possible to make $B = A$ using the following steps: - Choose $(l, r) = (2, 4)$, remove $\mathrm{mex}(\{1, 0, 3\}) = 2$ from $B$, making $B = (1, 0, 3)$. - Choose $(l, r) = (3, 3)$, remove $\mathrm{mex}(\{3\}) = 0$ from $B$, making $B = (1, 3)$. Thus, $P = (2, 1, 0, 3)$ satisfies the condition. There are eight permutations $P$ that satisfy the condition, including the above, so print $8$.
Input #2
4 4
0 3 2 1
Output #2
1
Only $P = (0, 3, 2, 1)$ satisfies the condition.
Input #3
16 7
9 2 4 0 1 6 7
Output #3
3520
Input #4
92 4
1 67 16 7
Output #4
726870122
Find the count modulo $998244353$.
题目信息
题号
arc178_d
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。