#6698. [ICPC 2025 Xi'an R] Mystique as Iris

    ID: 6698 传统题 1000ms 512MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>P14459动态规划 DP2025组合数学构造ICPCAd-hoc西安

[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 xx, decrease one of them by 11, and set the other to 00.
  • Remove all zeros from xx.

We call xx mystic\textit{mystic} 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 aa consisting of nn integers, as well as an integer mm. Each element of aa is either an integer from 11 to mm or −1-1. Your task is to replace every occurrence of −1-1 in aa with any integer from 11 to mm.

Determine the number of distinct mystic arrays aa that can be obtained after the replacement. Since the answer can be very large, output it modulo 109+710^9 + 7.

输入格式

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 nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤m1\le a_i \le m or ai=−1a_i=-1).

输出格式

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 −1-1-s with [1,1][1, 1] or with [2,1][2, 1], both sequences can also be reduced to empty. Therefore, the total number of distinct mystic sequences is 33. 标签: P14459|动态规划 DP|2025|组合数学|构造|ICPC|Ad-hoc|西安

来源

P14459|[ICPC 2025 Xi'an R] Mystique as Iris