atcoder#ARC120B. [ARC120B] Uniformly Distributed
[ARC120B] Uniformly Distributed
Score : points
Problem Statement
We have a grid with rows and columns. Let denote the square at the -th row and -th column. You are given strings that describe the square, as follows:
- if the -th character of is
R
, is painted red; - if the -th character of is
B
, is painted blue; - if the -th character of is
.
, is unpainted.
Let be the number of unpainted squares. Among the ways to paint each of those squares red or blue, how many satisfy the following condition?
- The number of red squares visited while getting from to by repeatedly moving one square right or down, including and , is always the same regardless of the path taken.
Since the count may be enormous, print it modulo .
Constraints
- is a string of length consisting of
R
,B
, and.
.
Input
Input is given from Standard Input in the following format:
Output
Print the count modulo .
2 2
B.
.R
2
There are two ways to get from to by repeatedly moving right or down, as follows:
If we paint and in different colors, the above two paths will contain different numbers of red squares, violating the condition. On the other hand, if we paint and in the same color, the two paths will contain the same numbers of red squares, satisfying the condition. Thus, there are two ways to satisfy the condition.
3 3
R.R
BBR
...
0
There may be no way to satisfy the condition.
2 2
BB
BB
1
There is no unpainted square, and the current grid satisfies the condition, so the answer is .