Problem Statement
There is a grid with $H$ rows and $W$ columns where each square has one of the characters X and Y written on it. Let $(i, j)$ denote the square at the $i$-th row from the top and $j$-th column from the left. The characters on the grid are given as $H$ strings $S_1, S_2, \dots, S_H$: the $j$-th character of $S_i$ is the character on square $(i, j)$.
For a path $P$ from square $(1, 1)$ to square $(H, W)$ obtained by repeatedly moving down or right to the adjacent square, the score is defined as follows.
- Let
$\mathrm{str}(P)$be the string of length$(H + W - 1)$obtained by concatenating the characters on the squares visited by$P$in the order they are visited. - The score of
$P$is the square of the number of pairs of consecutiveYs in$\mathrm{str}(P)$.
There are $\displaystyle\binom{H + W - 2}{H - 1}$ such paths. Find the sum of the scores over all those paths, modulo $998244353$.
What is $\binom{N}{K}$? $\displaystyle\binom{N}{K}$ is the binomial coefficient representing the number of ways to choose $K$ from $N$ distinct elements.
Constraints
$1 \leq H \leq 2000$$1 \leq W \leq 2000$$S_i \ (1 \leq i \leq H)$is a string of length$W$consisting ofXandY.
Input
The input is given from Standard Input in the following format:
H W
S_1
S_2
\vdots
S_H
Output
Print the sum of the scores over all possible paths, modulo $998244353$.
样例
2 2
YY
XY
4
2 2
XY
YY
2
10 20
YYYYYYYYYYYYYYYYYYYY
YYYYYYYYYYYYYYYYYYYY
YYYYYYYYYYYYYYYYYYYY
YYYYYYYYYYYYYYYYYYYY
YYYYYYYYYYYYYYYYYYYY
YYYYYYYYYYYYYYYYYYYY
YYYYYYYYYYYYYYYYYYYY
YYYYYYYYYYYYYYYYYYYY
YYYYYYYYYYYYYYYYYYYY
YYYYYYYYYYYYYYYYYYYY
423787835
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。