#6698. [ICPC 2025 Xi'an R] Mystique as Iris
[ICPC 2025 Xi'an R] Mystique as Iris
[ICPC 2025 Xi'an R] Mystique as Iris
题目描述
The following two steps, on an array $x$ consisting of positive integers, are called an operation:- Select any two adjacent elements in , decrease one of them by , and set the other to .
- Remove all zeros from .
We call if and only if it can be transformed into an empty sequence after a finite number of operations (possibly zero).
You are given an array consisting of integers, as well as an integer . Each element of is either an integer from to or . Your task is to replace every occurrence of in with any integer from to .
Determine the number of distinct mystic arrays that can be obtained after the replacement. Since the answer can be very large, output it modulo .
输入格式
The first line of the input contains two integers $n$ and $m$ ($2 \le n \le 10^6$, $1 \le m \le 10^8$).The second line of the input contains integers ( or ).
输出格式
Output a single integer, representing the number of distinct mystic sequences $a$ that can be obtained, modulo $10^9 + 7$.2 2
-1 -1
3
6 10
-1 -1 -1 -1 1 7
9125
提示
In the first test, the array $a$ is $[-1, -1]$. By replacing both $-1$-s, one possible result is $[1, 2]$. In this case, we select the two adjacent numbers: decrease the first by $1$ and set the second to $0$, obtaining $[0, 0]$. After removing all zeros, the sequence becomes empty. Hence, $[1, 2]$ is a mystic sequence.Similarly, if we replace the -s with or with , both sequences can also be reduced to empty. Therefore, the total number of distinct mystic sequences is . 标签: P14459|动态规划 DP|2025|组合数学|构造|ICPC|Ad-hoc|西安