luogu#P9682. Electro Master

    ID: 8926 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划 DP洛谷原创O2优化组合数学洛谷月赛

Electro Master

Background

I might be wrong.

Problem Description

Consider a system consisting of four types of microscopic particles: positive/negative A particles a+,a\text{a}^+,\text{a}^-, and positive/negative B particles b+,b\text{b}^+,\text{b}^-.

At the beginning, nn 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 a\text{a}^- and b+\text{b}^+ collide, a\text{a}^- becomes b\text{b}^-, and b+\text{b}^+ becomes a+\text{a}^+, 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 998244353998\,244\,353.

Input Format

Input one line containing a string ss of length nn, representing the charges of the A particles from left to right. Specifically:

  • If sis_i is +, then the ii-th A particle is positively charged;
  • If sis_i is -, then the ii-th A particle is negatively charged;
  • If sis_i is ?, then the ii-th A particle may be positive or negative.

Output Format

Output one line with one number, representing the result modulo 998244353998\,244\,353.

+?+-
1
??+-?-+
11
-????-?+?--????
2523

Hint

Explanation of Sample 1

There are two possible fillings: +++- and +-+-. Their weights are 0,10,1 respectively, so the final answer is 11.

Constraints

For all testdata, it is guaranteed that 1n20001\le n\le 2000, and si{+,-,?}s_i\in \{\texttt{+},\texttt{-},\texttt{?}\}.

# nn\le Special Property Score
0 - Sample 00
1 100100 There is no ? in ss 1010
2 - 2020
3 300300 The number of ? in ss does not exceed 1515 1515
4 - 2020
5 - 3535

Translated by ChatGPT 5