AtCoder Regular Contest 170
翻译中…
Problem Statement
翻译中…
For a sequence $X$ composed of a finite number of non-negative integers, we define $\mathrm{mex}(X)$ as the smallest non-negative integer not in $X$. For example, $\mathrm{mex}((0,0, 1,3)) = 2, \mathrm{mex}((1)) = 0, \mathrm{mex}(()) = 0$.
翻译中…
You are given a sequence $S=(S_1,\ldots,S_N)$ of length $N$ where each element is $0$ or $1$.
翻译中…
Find the number, modulo $998244353$, of sequences $A=(A_1,A_2,\ldots,A_N)$ of length $N$ consisting of integers between $0$ and $M$, inclusive, that satisfy the following condition:
翻译中…
- For each
$i (1\leq i\leq N)$,$A_i = \mathrm{mex}((A_1,A_2,\ldots,A_{i-1}))$if$S_i=1$, and$A_i \neq \mathrm{mex}((A_1,A_2,\ldots,A_{i-1}))$if$S_i=0$.
翻译中…
Constraints
翻译中…
$1 \leq N \leq 5000$$0 \leq M \leq 10^9$$S_i$is$0$or$1$.- All input numbers are integers.
翻译中…
Input
翻译中…
The input is given from Standard Input in the following format:
翻译中…
N M
S_1 \ldots S_N
翻译中…
Output
翻译中…
Print the answer.
翻译中…
样例
Input #1
4 2
1 0 0 1
Output #1
4
The following four sequences satisfy the conditions:
- $(0,0,0,1)$
- $(0,0,2,1)$
- $(0,2,0,1)$
- $(0,2,2,1)$
Input #2
10 1000000000
0 0 1 0 0 0 1 0 1 0
Output #2
587954969
Be sure to find the count modulo $998244353$.
题目信息
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。