Codeforces Round 596 (Div. 1, based on Technocup 2020 Elimination Round 2)
C
Rock Is Push
Codeforces
未评级
原题
← BD →
翻译中…

You are at the top left cell $(1, 1)$ of an $n \times m$ labyrinth. Your goal is to get to the bottom right cell $(n, m)$. You can only move right or down, one cell per step. Moving right from a cell $(x, y)$ takes you to the cell $(x, y + 1)$, while moving down takes you to the cell $(x + 1, y)$.

翻译中…

Some cells of the labyrinth contain rocks. When you move to a cell with rock, the rock is pushed to the next cell in the direction you're moving. If the next cell contains a rock, it gets pushed further, and so on.

翻译中…

The labyrinth is surrounded by impenetrable walls, thus any move that would put you or any rock outside of the labyrinth is illegal.

翻译中…

Count the number of different legal paths you can take from the start to the goal modulo $10^9 + 7$. Two paths are considered different if there is at least one cell that is visited in one path, but not visited in the other.

翻译中…

Input

翻译中…

The first line contains two integers $n, m$ — dimensions of the labyrinth ($1 \leq n, m \leq 2000$).

翻译中…

Next $n$ lines describe the labyrinth. Each of these lines contains $m$ characters. The $j$-th character of the $i$-th of these lines is equal to "R" if the cell $(i, j)$ contains a rock, or "." if the cell $(i, j)$ is empty.

翻译中…

It is guaranteed that the starting cell $(1, 1)$ is empty.

翻译中…

Output

翻译中…

Print a single integer — the number of different legal paths from $(1, 1)$ to $(n, m)$ modulo $10^9 + 7$.

翻译中…

Note

翻译中…

In the first sample case we can't (and don't have to) move, hence the only path consists of a single cell $(1, 1)$.

翻译中…

In the second sample case the goal is blocked and is unreachable.

翻译中…

Illustrations for the third sample case can be found here: https://assets.codeforces.com/rounds/1225/index.html

翻译中…

样例

Input #1
1 1
.
Output #1
1
InputCopy OutputCopy
Input #2
2 3
...
..R
Output #2
0
InputCopy OutputCopy
Input #3
4 4
...R
.RR.
.RR.
R...
Output #3
4
InputCopy OutputCopy
题目信息
题号
1246C
时间限制
2 s
内存限制
512 MB

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。