#P7512. 「Byakkai OI 2021」Eaquira
「Byakkai OI 2021」Eaquira
Description
Given , take the integer points on the number line in .
Define a maximal consecutive black segment as an interval with , such that all intervals with indices in are black, and it cannot be extended further; that is, the intervals with indices (if it exists; same below) and are both white.
First, you need to partition them into several intervals , satisfying , , and for we have ; for we have .
Second, you need to mark each interval as black or white, but it is not allowed that both the first interval and the -th interval are marked black at the same time.
Third, within each interval, select a subinterval, called a wonderful subinterval.
Fourth, in each maximal consecutive black segment, select one black interval, called a wonderful black interval.
Fifth, among all maximal consecutive black segments, designate some of them as wonderful maximal consecutive black segments.
Define the weight of a plan determined by the above steps as the sum of the number of black intervals and the number of wonderful maximal consecutive black segments.
Originally, I hoped you would compute, for , the number of plans that make the final weight equal to . However, I have also prepared some easier challenges. See the input format for details.
The answer should be taken modulo .
Input Format
One line with two integers .
If , you need to compute, for , the number of plans with weight .
If , you need to compute the total number of plans over all .
Output Format
If , output one line with non-negative integers, in order, representing the answers for .
If , output one line with one non-negative integer, representing the answer.
3 0
6 13 17 4
5 1
1035
Hint
Sample Explanation
Below, denotes black and denotes white.
For the first sample, consider the partitions of :
- :
At this time, the number of ways to choose an unordered pair is .
Considering the black/white marking of each interval, there are the following plans:- : in this case, you may choose whether to mark the only maximal consecutive black segment as wonderful or not, so the weight is or . The number of ways to choose the wonderful black interval is .
- : in this case, you may choose whether to mark the only maximal consecutive black segment as wonderful or not, so the weight is or . The number of ways to choose the wonderful black interval is .
- or :
At this time, the number of ways to choose an unordered pair is .
Considering the black/white marking of each interval, there are the following plans:- : in this case, you may choose whether to mark the only maximal consecutive black segment as wonderful or not, so the weight is or . The number of ways to choose the wonderful black interval is .
- :
At this time, the number of ways to choose an unordered pair is .
Considering the black/white marking of each interval, there is the following plan:- : in this case, the weight is , the total number of plans is , and the number of ways to choose the wonderful black interval is . Therefore, the number of plans with weight is , the number of plans with weight is , the number of plans with weight is $1 \times 2 \times 2 + 1 \times 1 + 2 \times 3 \times 2 \times 1 = 17$, and the number of plans with weight is .
For the second sample, no explanation is provided.
Constraints
This problem uses bundled testdata.
The specific subtask constraints and scores are as follows:
| Subtask ID | Score | Time limit / s | ||
|---|---|---|---|---|
For all testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号