luogu#P9682. Electro Master
Electro Master
Background
I might be wrong.
Problem Description
Consider a system consisting of four types of microscopic particles: positive/negative A particles , and positive/negative B particles .
At the beginning, A particles are placed on a straight line. Then, in some way, each particle is given an initial velocity so that positively charged particles move to the left, and negatively charged particles move to the right. We ignore interactions between particles, assuming that after acceleration each particle moves at a constant speed and all motion stays on the line.
When two particles collide, they bounce back and continue moving in the opposite directions. At the same time, the following transformation rules apply:
- If the two particles have the same charge, nothing happens;
- If the two particles have different charges, they both change into the other species with the same charge.
For example, when and collide, becomes , and becomes , and each continues moving in the opposite direction.
Define the weight of an arrangement as the number of B particles collected on the left side after a sufficiently long time.
Now, the charges (positive/negative) of some A particles have been fixed, while the remaining A particles may be positive or negative. Please compute the sum of the weights over all possible assignments.
You need to output the answer modulo .
Input Format
Input one line containing a string of length , representing the charges of the A particles from left to right. Specifically:
- If is
+, then the -th A particle is positively charged; - If is
-, then the -th A particle is negatively charged; - If is
?, then the -th A particle may be positive or negative.
Output Format
Output one line with one number, representing the result modulo .
+?+-
1
??+-?-+
11
-????-?+?--????
2523
Hint
Explanation of Sample 1
There are two possible fillings: +++- and +-+-. Their weights are respectively, so the final answer is .
Constraints
For all testdata, it is guaranteed that , and .
| # | Special Property | Score | |
|---|---|---|---|
| 0 | - | Sample | |
| 1 | There is no ? in |
||
| 2 | - | ||
| 3 | The number of ? in does not exceed |
||
| 4 | - | ||
| 5 | - |
Translated by ChatGPT 5