#P6576. [BalticOI 2017] Plus Minus
[BalticOI 2017] Plus Minus
Description
The chip has size , and it can be divided into electrons.
As we all know, an electron can only be in one of two states: positive + or negative -.
So, each electron has exactly one state, either + or -.
Matthew does not know the state of each electron, but he can perform measurements.
In the -th measurement, he can obtain the state of the electron at position .
( is + or -.)
Matthew also knows that in any block of electrons, the number of + electrons equals the number of - electrons.
Then he came to you and asked you to determine how many electron arrangements satisfy the measurement results and the requirement above.
Output the answer modulo .
Input Format
The first line contains three integers , representing the chip size and the number of measurements.
The next lines each contain a character (the state observed in this measurement) and the integers (the measured position).
Output Format
Output one integer: the number of valid electron arrangements.
Output the answer modulo .
2 4 4
+ 1 1
- 1 2
+ 1 3
- 1 4
2
3 3 3
- 2 1
+ 2 3
+ 3 3
0
Hint
Sample Explanation
For sample , there are the following cases:
+-+-
+-+-
and
+-+-
-+-+
Constraints
This problem uses bundled testdata.
- Subtask 1 (12 pts): .
- Subtask 2 (42 pts): .
- Subtask 3 (46 pts): no special constraints.
For of the testdata, , , , and .
Note
Translated from BOI 2017 D2 T3 Plus Minus.
Translator: @一只书虫仔。
Translated by ChatGPT 5
京公网安备 11011102002149号