题目收集
题目列表题单
返回列表

Shugenja

CodeforcesP0011· 2000ms· 512 MB· ZJU Summer 2026 Contest 1原题链接
dp数据结构优化

创建于 2026/07/16 · 更新于 2026/07/16

题目描述

There are nnn people standing in a line, and at least one of them is evil.

Each person has a status: evil or non-evil. Each person also gives a piece of information, saying whether the nearest evil person to them is on their left or on their right. If the nearest evil people on both sides are at the same distance, the person will say "left". In particular, if a person is evil, they may give arbitrary information.

However, the information given by some people is uncertain.

You need to determine the number of possible scenarios. Two scenarios are considered different if and only if there exists at least one person whose status differs, or whose given information differs.

输入格式

The first line contains an integer nnn (1≤n≤5×1051 \le n \le 5 \times 10^51≤n≤5×105), denoting the number of people.

The second line contains a string sss of length nnn. Each character of sss is one of the following:

  • L: the person says that the nearest evil person is on their left;
  • R: the person says that the nearest evil person is on their right;
  • ?: the information given by this person is uncertain.

输出格式

Print a single integer - the answer modulo 998244353998244353998244353.

样例输入 #1

3
L??

样例输出 #1

9

样例输入 #2

5
?LR??

样例输出 #2

57