#5048. Problem 2. Interstellar Intervals
Problem 2. Interstellar Intervals
Problem 2. Interstellar Intervals
USACO 2024 December Contest, Gold
It's the year , and Bessie became the first cow in space! During her journey between the stars, she found a number line with () points, numbered from to . All points are initially colored white. She can perform the following operation any number of times.
- Choose a position within the number line and a positive integer . Then, color all the points in the interval red and all points in blue. All chosen intervals must be disjoint (i.e. no points in can be already colored red or blue). The entire interval must also fall within the number line (i.e. ).
Farmer John gives Bessie a string of length consisting of characters , , and . The string represents Farmer John's color preferences for each point: means the 'th point must be colored red, means the 'th point must be colored blue, and means there is
no constraint
on the color for the '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 .
INPUT FORMAT (input arrives from the terminal / stdin):
The first line contains an integer .
The following line contains string .
OUTPUT FORMAT (print output to the terminal / stdout):
Output the number of distinct ways for the number line to be colored while satisfying Farmer John's preferences modulo .
SAMPLE INPUT:
6 RXXXXB
SAMPLE OUTPUT:
5
Bessie can choose (i.e. color point red and point blue) and (i.e. color points red and points blue) to produce the coloring .
The other colorings are , , , and .
SAMPLE INPUT:
6 XXRBXX
SAMPLE OUTPUT:
6
The six colorings are , , , , , and .
SAMPLE INPUT:
12 XBXXXXRXRBXX
SAMPLE OUTPUT:
18
SCORING: Input 4: Inputs 5-6: Inputs 7-13: All but at most characters in are .Inputs 14-23: No additional constraints
Problem credits: Chongtian Ma, Alex Liang