#abc238h. Ex - Removing People

Ex - Removing People

Score : 600600 points

问题描述

设有NN个人,编号为11NN,他们按照顺时针顺序站成一个圆圈:第11个人、第22个人、\cdots、第NN个人。每个人面向的方向由长度为NN的字符串SS给出。对于每个ii (1iN)(1 \leq i \leq N),如果Si=S_i = L,则第ii个人面向逆时针方向;如果Si=S_i = R,则第ii个人面向顺时针方向。

接下来将重复进行N1N-1次以下操作:

  • 等概率地选择一个剩余的人,然后从圆圈中移除从该人选出的人看到的最近的人。这次操作的成本等于选出的人到被移除的人的距离。

这里,从第ii个人到第jj个人(ij)(i \neq j)的距离定义如下:

  1. 当第ii个人面向顺时针方向时:
    • 如果i<ji < j,距离为jij-i
    • 如果i>ji > j,距离为ji+Nj-i+N
  2. 当第ii个人面向逆时针方向时:
    • 如果i<ji < j,距离为ij+Ni-j+N
    • 如果i>ji > j,距离为iji-j

求总成本的期望值对998244353998244353取模的结果(参见注释)。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

NN people numbered 11 to NN are standing in a circle, in the clockwise order of Person 11, Person 22, \cdots, Person NN. The direction each person faces is given by a string SS of length NN. For each ii (1iN)(1 \leq i \leq N), Person ii is facing in the counter-clockwise direction if Si=S_i = L, and clockwise direction if Si=S_i = R.

The following operation will be repeated N1N-1 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 ii to Person jj (ij)(i \neq j) is defined as follows.

  1. When Person ii is facing in the clockwise direction:
    • jij-i if i<ji \lt j;
    • ji+Nj-i+N if i>ji \gt j.
  2. When Person ii is facing in the counter-clockwise direction:
    • ij+Ni-j+N if i<ji \lt j;
    • iji-j if i>ji \gt j.

Find the expected value of the total cost incurred, modulo 998244353998244353 (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 PQ\frac{P}{Q} using two coprime integers PP and QQ, there is a unique integer RR such that R×QP(mod998244353)R \times Q \equiv P\pmod{998244353} and 0R<9982443530 \leq R \lt 998244353. Find this RR.

Constraints

  • 2N3002 \leq N \leq 300
  • NN is an integer.
  • SS is a string of length NN consisting of L and R.

Input

Input is given from Standard Input in the following format:

NN

SS

Output

Print the answer.

Sample Input 1

3
LLR

Sample Output 1

831870297

The sought expected value is 176\frac{17}{6}. We have 831870297×617(mod998244353)831870297 \times 6 \equiv 17\pmod{998244353}, so 831870297831870297 should be printed.

For your reference, here is one possible scenario.

  1. Person 22 is chosen. The nearest person seen from Person 22 remaining in the circle is Person 11, who gets removed from the circle.
  2. Person 22 is chosen again. The nearest person seen from Person 22 remaining in the circle is Person 33, who gets removed from the circle.

In this case, the total cost incurred is 3(=1+2)3(=1+2).

Sample Input 2

10
RRRRRRLLRR

Sample Output 2

460301586

update @ 2024/3/10 10:18:36