RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
USACO0634

Interstellar Intervals

Diamond IV 다이아몬드 IV
난이도
2s
시간 제한
256MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

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\).

Problem credits: Chongtian Ma, Alex Liang

제약

SCORING

  • Input 4: \(N\le 500\)
  • Inputs 5-6: \(N\le 10^4\)
  • Inputs 7-13: All but at most \(100\) characters in \(s\) are \(X\).
  • Inputs 14-23: No additional constraints

Problem credits: Chongtian Ma, Alex Liang

입력 형식

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
출력
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
출력
6
설명

The six colorings are \(WWRBWW\), \(WWRBRB\), \(WRRBBW\), \(RBRBWW\), \(RBRBRB\), and \(RRRBBB\).

예제 3
입력
12
XBXXXXRXRBXX
출력
18
문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2024-2025 > December > Gold

태그

평가 및 의견

Interstellar Intervals

개요
출제자 난이도 Diamond IV 다이아몬드 IV 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Interstellar Intervals

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8