#abc357g. G - Stair-like Grid
G - Stair-like Grid
Score : points
问题陈述
有一个特殊的网格,有 行。( 是偶数。)从顶部数第 行有 个单元格从左端开始。 例如,当 时,网格看起来像下面这样:
用 表示从顶部数第 行和从左端数第 列的单元格。 每个单元格要么是空单元格,要么是墙单元格。有 个墙单元格,第 个墙单元格是 。这里, 和 是空的。 从 开始,通过反复向右或向下移动到相邻的空单元格,有多少种方法可以到达 ?找出计数模 。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
There is a special grid with rows. ( is even.) The -th row from the top has cells from the left end.
For example, when , the grid looks like the following:
Let denote the cell at the -th row from the top and -th column from the left.
Each cell is either an empty cell or a wall cell. There are wall cells, and the -th wall cell is . Here, and are empty.
Starting from , how many ways are there to reach by repeatedly moving right or down to an adjacent empty cell? Find the count modulo .
Constraints
- is even.
- $1 \leq b_i \leq \left \lceil \frac{a_i}{2} \right \rceil \times 2$
- and .
- if .
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the number of ways to reach from by repeatedly moving right or down to an adjacent empty cell, modulo .
Sample Input 1
4 2
2 1
4 2
Sample Output 1
2
There are two paths that satisfy the conditions of the problem:
- $(1, 1) \to (1, 2) \to (2, 2) \to (3, 2) \to (3, 3) \to (3, 4) \to (4, 4)$
- $(1, 1) \to (1, 2) \to (2, 2) \to (3, 2) \to (3, 3) \to (4, 3) \to (4, 4)$
Sample Input 2
6 3
2 1
3 3
4 2
Sample Output 2
0
Sample Input 3
100 10
36 9
38 5
38 30
45 1
48 40
71 52
85 27
86 52
92 34
98 37
Sample Output 3
619611437
Sample Input 4
100000 10
552 24
4817 255
7800 954
23347 9307
28028 17652
39207 11859
48670 22013
74678 53158
75345 45891
88455 4693
Sample Output 4
175892766