#P7213. [JOISC 2020] 最古の遺跡 3
[JOISC 2020] 最古の遺跡 3
Description
He discovered the ruins of a row of ancient stone pillars and an ancient document.
The ancient document states the following:
- When it was just completed, there were stone pillars. For each , there were exactly two pillars of height . Let the height of the -th pillar be .
- There will be earthquakes. Each earthquake decreases the height of some pillars by , while the heights of the other pillars remain unchanged.
- During an earthquake, the height of pillar does not change if and only if and for all , we have .
- After earthquakes, exactly pillars remain.
Now Professor JOI has found the positions of the remaining pillars. He wants you to compute the number of possible initial construction plans for the heights of the pillars, modulo .
Input Format
The first line contains an integer .
The next line contains numbers, representing .
Output Format
Output a single integer: the number of possible initial construction plans for the heights of the pillars, modulo .
3
3 4 6
5
1
1
0
10
5 8 9 13 15 16 17 18 19 20
147003663
Hint
Sample Explanation
Sample 1 Explanation
One feasible solution is .
- After the first earthquake, it becomes .
- After the second earthquake, it becomes .
- After the third earthquake, it becomes .
The other four solutions are:
- .
- .
- .
- .
Sample 2 Explanation
For the case , clearly there is only one construction plan: . After one earthquake, it becomes , so it is impossible for there to be a pillar at position .
Sample 3 Explanation
There are possible construction plans in total, and .
Subtasks
For of the testdata, it is guaranteed that , , and .
| Subtask ID | Score | |
|---|---|---|
| None |
Notes
This problem is translated from Day 2 T3 The Oldest Ruins 3 of The 19th Japanese Olympiad in Informatics Spring Training Camp.
Translated by ChatGPT 5
京公网安备 11011102002149号