atcoder#ARC157C. [ARC157C] YY Square
[ARC157C] YY Square
Score : points
Problem Statement
There is a grid with rows and columns where each square has one of the characters X and Y written on it.
Let denote the square at the -th row from the top and -th column from the left.
The characters on the grid are given as strings : the -th character of is the character on square .
For a path from square to square obtained by repeatedly moving down or right to the adjacent square, the score is defined as follows.
- Let be the string of length obtained by concatenating the characters on the squares visited by in the order they are visited.
- The score of is the square of the number of pairs of consecutive
Ys in .
There are such paths. Find the sum of the scores over all those paths, modulo .
What is $\binom{N}{K}$?
\displaystyle\binom{N}{K}$$$$K$$$$NConstraints
- is a string of length consisting of
XandY.
Input
The input is given from Standard Input in the following format:
Output
Print the sum of the scores over all possible paths, modulo .
2 2
YY
XY
4
There are two possible paths : and .
- For , we have
YYY, with two pairs of consecutiveYs at positions and , so the score is . - For , we have
YXY, with no pairs of consecutiveYs , so the score is .
Thus, the sought sum is .
2 2
XY
YY
2
For either of the two possible paths , we have XYY, for a score of .
10 20
YYYYYYYYYYYYYYYYYYYY
YYYYYYYYYYYYYYYYYYYY
YYYYYYYYYYYYYYYYYYYY
YYYYYYYYYYYYYYYYYYYY
YYYYYYYYYYYYYYYYYYYY
YYYYYYYYYYYYYYYYYYYY
YYYYYYYYYYYYYYYYYYYY
YYYYYYYYYYYYYYYYYYYY
YYYYYYYYYYYYYYYYYYYY
YYYYYYYYYYYYYYYYYYYY
423787835
Print the sum of the scores modulo .