atcoder#KEYENCE2021C. Robot on Grid
Robot on Grid
Score : points
Problem Statement
We have a grid with rows and columns of squares. Let denote the square at the -th row from the top and -th column from the left.
On each square, we can write a letter: R
, D
, or X
. Initially, every square is empty.
Snuke chose of the squares and wrote characters on them. The -th square he chose was , and he wrote the letter on it.
There are ways to write a letter on each of the remaining squares. Find the sum of the answers to the problem below for all those ways, modulo .
We have a robot that can walk on the grid. When it is at , it can move to or .
However, ifR
is written on , it can only move to ; ifD
is written on , it can only move to . IfX
is written on , both choices are possible.When the robot is put at , how many paths can the robot take to reach without going out of the grid? We assume the robot halts when reaching .
Here, we distinguish two paths when the sets of squares traversed by the robot are different.
Constraints
- for .
- is
R
,D
, orX
.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
2 2 3
1 1 X
2 1 R
2 2 R
5
- Only is empty.- If we write
R
on it, there is one way that the robot can take to reach .- If we write
D
on it, there are two ways that the robot can take to reach . - If we write
X
on it, there are two ways that the robot can take to reach .
- If we write
- If we write
R
on it, there is one way that the robot can take to reach . - If we write
D
on it, there are two ways that the robot can take to reach . - If we write
X
on it, there are two ways that the robot can take to reach . - We should print the sum of these counts: .
3 3 5
2 3 D
1 3 D
2 1 D
1 2 X
3 1 R
150
5000 5000 10
585 1323 R
2633 3788 X
1222 4989 D
1456 4841 X
2115 3191 R
2120 4450 X
4325 2864 X
222 3205 D
2134 2388 X
2262 3565 R
139923295
- Be sure to compute the sum modulo .