#abc238h. Ex - Removing People
Ex - Removing People
Score : points
问题描述
设有个人,编号为至,他们按照顺时针顺序站成一个圆圈:第个人、第个人、、第个人。每个人面向的方向由长度为的字符串给出。对于每个 ,如果 L
,则第个人面向逆时针方向;如果 R
,则第个人面向顺时针方向。
接下来将重复进行次以下操作:
- 等概率地选择一个剩余的人,然后从圆圈中移除从该人选出的人看到的最近的人。这次操作的成本等于选出的人到被移除的人的距离。
这里,从第个人到第个人的距离定义如下:
- 当第个人面向顺时针方向时:
- 如果,距离为;
- 如果,距离为。
- 当第个人面向逆时针方向时:
- 如果,距离为;
- 如果,距离为。
求总成本的期望值对取模的结果(参见注释)。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
people numbered to are standing in a circle, in the clockwise order of Person , Person , , Person . The direction each person faces is given by a string of length . For each , Person is facing in the counter-clockwise direction if L
, and clockwise direction if R
.
The following operation will be repeated times.
- Choose one of the remaining people with equal probability, and remove from the circle the nearest person seen from the chosen person. This incurs a cost equal to the distance from the chosen person to the removed person.
Here, the distance from Person to Person is defined as follows.
- When Person is facing in the clockwise direction:
- if ;
- if .
- When Person is facing in the counter-clockwise direction:
- if ;
- if .
Find the expected value of the total cost incurred, modulo (see Notes).
Notes
It can be proved that the sought expected value is always a rational number. Additionally, under the Constraints of this problem, when that value is expressed as using two coprime integers and , there is a unique integer such that and . Find this .
Constraints
- is an integer.
- is a string of length consisting of
L
andR
.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
3
LLR
Sample Output 1
831870297
The sought expected value is . We have , so should be printed.
For your reference, here is one possible scenario.
- Person is chosen. The nearest person seen from Person remaining in the circle is Person , who gets removed from the circle.
- Person is chosen again. The nearest person seen from Person remaining in the circle is Person , who gets removed from the circle.
In this case, the total cost incurred is .
Sample Input 2
10
RRRRRRLLRR
Sample Output 2
460301586
update @ 2024/3/10 10:18:36