Bocchi the Rock

시간 제한10초메모리 제한2048 MB

요약
원 위 n개의 점과 n개의 호에 색을 칠할 때, 같은 색 점끼리 교차하지 않는 현을 그어 모든 영역이 단색이 되도록 하는 색칠의 수를 일부 색이 고정된 조건에서 센다.
난이도

어려움10점 중 8점

유형
조합론, 동적 계획법, 수학
정답자
아직 제출이 없습니다

문제

Given a circle divided into nn arcs by nn distinct points lying on it, your task is to determine the number of valid colorings that satisfy certain conditions. Each point on the circle can be colored either red or blue, and each arc can be colored either yellow or pink. Chords can be added between points of the same color, with the restriction that a chord cannot connect a red point and a blue point. No two chords can intersect. Additionally, each point should be connected to at most one chord. Once all chords are added, the circle is divided into various regions by these chords.

A coloring is considered good if it is possible to add chords in such a way that each region in the resulting division is monochrome. A region is considered monochrome if it does not include arcs of both colors. Your goal is to calculate the number of such good colorings, taking into account the designated colors of certain points and arcs.

Calculate the number of valid colorings modulo 998,244,353998\\,244\\,353, given the initial colors of some points and arcs.

입력

The first line contains an integer nn (2≤n≤5⋅1042 \leq n \leq 5 \cdot 10^4). The second line contains a string s=s_1s_2…s_2ns = s\_1 s\_2 \ldots s\_{2n}, representing the color types of the arcs and points.

For every odd ii, character s_is\_i can only be "Y", "P", or "?", meaning that the color of i+12\frac{i+1}{2}-th arc is yellow, pink, or can be both colors, respectively.

For every even ii, character s_is\_i can only be "R", "B", or "?", meaning that the color of i2\frac{i}{2}-th point is red, blue, or can be both colors, respectively.

출력

Print a line with a single integer: the number of valid colorings modulo 998,244,353998\\,244\\,353.

힌트

In example 1, the 1212 valid colorings are: YBYB, YBYR, YRYB, YRYR, PBPB, PBPR, PRPB, PRPR, YBPB, YRPR, PBYB, PRYR.

In example 2, the following figures aid in visual understanding.

The left figure shows the circle before coloring; the middle figure represents a valid coloring as PBYRYB, and we can connect two points colored as B with a chord to prove that the coloring is good; the right figure represents an invalid coloring as PBYRPB.

예제3

  1. 예제 1

    입력
    2
    ????
    
    예상 출력
    12
    
  2. 예제 2

    입력
    3
    ??YR?B
    
    예상 출력
    4
    
  3. 예제 3

    입력
    5
    YBYRPBYRYB
    
    예상 출력
    0