#P11426. Circular Arrangement Game Score

    ID: 13505 Type: Default 1000ms 256MiB

Circular Arrangement Game Score

Circular Arrangement Game Score

We are given ( n ) contestants numbered (1, 2, \dots, n). Each contestant ( i ) has strength equal to ( i ) and is assigned to one of two teams according to a given string ( s ) of length ( n ): if ( s_i = R ), then contestant ( i ) is on the red team; if ( s_i = B ), then contestant ( i ) is on the blue team.

All contestants are arranged in a circle. For every pair of adjacent contestants (neighbors in the circle) who belong to different teams, a match is held. In each match the contestant with the higher strength (i.e. larger index) wins and his team would normally receive one point. However, there is a twist: if the winning contestant is from the red team and is located in the clockwise direction relative to the blue contestant in the match, then due to collusion the match is cancelled (no point is awarded).

More precisely, consider an adjacent pair ((a, b)) where contestant ( b ) is the clockwise neighbour of contestant ( a ). There are two cases when ( a ) and ( b ) are from different teams:

  1. If ( a ) is red and ( b ) is blue, then:

    • If ( a > b ) (i.e. contestant ( a ) is stronger), red wins and the match is valid (red earns +1 point).
    • Otherwise (( a < b )), blue wins and blue earns +1 point (contributing ( -1 ) to red minus blue score).
  2. If ( a ) is blue and ( b ) is red, then:

    • If ( b > a ) (red would win), the win is cancelled due to collusion (no points awarded).
    • Otherwise (( b < a )), blue wins and blue earns +1 point.

Let the final score difference be defined as (red team score) minus (blue team score). Two arrangements of the contestants are considered different if and only if there exists at least one contestant whose immediate clockwise neighbour differs between the two arrangements. (Note that in a circle, rotations are considered the same arrangement; hence one may fix a position to break the rotational symmetry.)

Your task is: given ( n ) and the string ( s ), for each ( k = -n, -n+1, \dots, -1, 0, 1, \dots, n ) compute the number of distinct arrangements (modulo (998244353)) in which the final score difference is exactly ( k ).

( \textbf{Input constraints:} ) For this version, you may assume ( n ) is small enough (e.g. ( n \le 8 )) so that a brute force solution is acceptable.

inputFormat

The input consists of two lines:

  • The first line contains an integer ( n ) (the number of contestants).
  • The second line contains a string ( s ) of length ( n ) where each character is either 'R' or 'B', representing the team of contestant ( i ) (( 1 \le i \le n )).

outputFormat

Output ( 2n+1 ) space‐separated integers. The ( i)th integer corresponds to the number of distinct circular arrangements (modulo (998244353)) yielding a final score difference of ( k ) where ( k ) runs from ( -n ) to ( n ) in increasing order.

sample

3
RBR
0 0 1 1 0 0 0