Logo
(追記) (追記ここまで)

33057번 - Interstellar Intervals 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 2048 MB48211952.778%

문제

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

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

Farmer John gives Bessie a string $s$ of length $N$ consisting of characters $R,ドル $B,ドル and $X$. The string represents Farmer John's color preferences for each point: $s_i=R$ means the $i$'th point must be colored red, $s_i = B$ means the $i$'th point must be colored blue, and $s_i = X$ means there is no constraint on the color for the $i$'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 10ドル^9+7$.

입력

The first line contains an integer $N$.

The following line contains string $s$.

출력

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

제한

예제 입력 1

6
RXXXXB

예제 출력 1

5
Bessie can choose $i=1,x=1$ (i.e. color point 1ドル$ red and point 2ドル$ blue) and $i=3,x=2$ (i.e. color points 3,4ドル$ red and points 5,6ドル$ blue) to produce the coloring $RBRRBB$.

The other colorings are $RRBBRB,ドル $RBWWRB,ドル $RRRBBB,ドル and $RBRBRB$.

예제 입력 2

6
XXRBXX

예제 출력 2

6

The six colorings are $WWRBWW,ドル $WWRBRB,ドル $WRRBBW,ドル $RBRBWW,ドル $RBRBRB,ドル and $RRRBBB$.

예제 입력 3

12
XBXXXXRXRBXX

예제 출력 3

18

힌트

출처

Olympiad > USA Computing Olympiad > 2024-2025 Season > USACO 2024 December Contest > Gold 2번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /