#arc170c. C - Prefix Mex Sequence
C - Prefix Mex Sequence
Score: points
问题陈述
对于一个由有限数量的非负整数组成的序列 ,我们定义 为不在 中的最小非负整数。例如,$\mathrm{mex}((0,0, 1,3)) = 2, \mathrm{mex}((1)) = 0, \mathrm{mex}(()) = 0$。
给定一个长度为 的序列 ,其中每个元素是 或 。
找到长度为 的序列 的数量,这些序列由 到 (包括 )之间的整数组成,满足以下条件:
- 对于每个 ,如果 ,则 ;如果 ,则 。
结果需要模 。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
For a sequence composed of a finite number of non-negative integers, we define as the smallest non-negative integer not in . For example, $\mathrm{mex}((0,0, 1,3)) = 2, \mathrm{mex}((1)) = 0, \mathrm{mex}(()) = 0$.
You are given a sequence of length where each element is or .
Find the number, modulo , of sequences of length consisting of integers between and , inclusive, that satisfy the following condition:
- For each , if , and if .
Constraints
- is or .
- All input numbers are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
4 2
1 0 0 1
Sample Output 1
4
The following four sequences satisfy the conditions:
Sample Input 2
10 1000000000
0 0 1 0 0 0 1 0 1 0
Sample Output 2
587954969
Be sure to find the count modulo .