#P8159. 「PMOI-5」一道防不住 AK 的水题
「PMOI-5」一道防不住 AK 的水题
Background
The enhanced version of this problem is here.
Problem Description
There are boxes and operations. The boxes are numbered from . The -th operation will run for a total of rounds. In the -th round, balls are put into the box numbered (where is enumerated starting from ).
After all operations are completed, you need to choose different boxes such that no two chosen boxes have adjacent indices. Define the value of one selection as the product of the numbers of balls in these boxes. Find the sum of the values of all valid selections modulo .
Input Format
The first line contains four integers , representing the number of operations, the two parameters related to the operations, and the number of boxes to be chosen.
The next lines each contain four non-negative integers , describing the parameters of an operation.
Output Format
Output one integer, which is the sum of values modulo .
2 3 5 2
1 3 2 2
2 3 1 1
13
3 89 1000000 4
2 222 19 2
4 66666 1 9
5 114514 8 10
299126098
Hint
This problem uses bundled testdata.
- Subtask 1 (10 pts): .
- Subtask 2 (5 pts): .
- Subtask 3 (30 pts): , .
- Subtask 4 (30 pts): and are coprime.
- Subtask 5 (25 pts): No special constraints.
For of the testdata, , , , , , , and .
Translated by ChatGPT 5