Interstellar Intervals

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

요약
같은 길이의 빨강·파랑 구간 쌍을 겹치지 않게 배치해 N개 점을 칠할 때, R/B/X 제약을 만족하는 색칠의 수를 센다.
난이도

어려움10점 중 9점

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

문제

It's the year 30003000, and Bessie became the first cow in space! During her journey between the stars, she found a number line with NN (2≤N≤5⋅1052 \leq N \leq 5 \cdot 10^5) points, numbered from 11 to NN. All points are initially colored white. She can perform the following operation any number of times.

  • Choose a position ii within the number line and a positive integer xx. Then, color all the points in the interval \[i,i+x−1]\[i, i + x - 1] red and all points in \[i+x,i+2x−1]\[i + x, i + 2x - 1] blue. All chosen intervals must be disjoint (i.e. no points in \[i,i+2x−1]\[i, i + 2x - 1] can be already colored red or blue). The entire interval must also fall within the number line (i.e. 1≤i≤i+2x−1≤N1 \leq i \leq i + 2x - 1 \leq N).

Farmer John gives Bessie a string ss of length NN consisting of characters RR, BB, and XX. The string represents Farmer John's color preferences for each point: s_i=Rs\_i=R means the ii'th point must be colored red, s_i=Bs\_i = B means the ii'th point must be colored blue, and s_i=Xs\_i = X means there is no constraint on the color for the ii'th point.

Help Bessie count the number of distinct ways for the number line to be colored while satisfying Farmer John's preferences. Two colorings are different if there is at least one corresponding point with a different color. Because the answer may be large, output it modulo 109+710^9+7.

입력

The first line contains an integer NN.

The following line contains string ss.

출력

Output the number of distinct ways for the number line to be colored while satisfying Farmer John's preferences modulo 109+710^9+7.

예제3

  1. 예제 1

    입력
    6
    RXXXXB
    
    예상 출력
    5
    
  2. 예제 2

    입력
    6
    XXRBXX
    
    예상 출력
    6
    
  3. 예제 3

    입력
    12
    XBXXXXRXRBXX
    
    예상 출력
    18