トヨタ自動車プログラミングコンテスト2024#11(AtCoder Beginner Contest 379)
G
Count Grid 3-coloring
AtCoder
⌀ 2304
原题
翻译中…

Problem Statement

翻译中…

You are given a grid $S$ with $H$ rows and $W$ columns consisting of 1, 2, 3, and ?. The character at the $i$-th row and $j$-th column is $S_{i,j}$.

翻译中…

By replacing each ? in $S$ with 1, 2, or 3, we can obtain $3^q$ different grids, where $q$ is the number of ?. Among these grids, how many satisfy the following condition? Print the count modulo $998244353$.

翻译中…
  • Any two adjacent (edge-sharing) cells contain different digits.
翻译中…

Constraints

翻译中…
  • $1 \leq H, W$
  • $H \times W \leq 200$
  • $H$ and $W$ are integers.
  • $S$ is a grid with $H$ rows and $W$ columns consisting of 1, 2, 3, and ?.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

H W
S_{1,1}S_{1,2}\ldots S_{1,W}
S_{2,1}S_{2,2}\ldots S_{2,W}
\vdots
S_{H,1}S_{H,2}\ldots S_{H,W}

翻译中…

Output

翻译中…

Print the answer.

翻译中…

样例

Input #1
2 2
1?
??
Output #1
6
Among the grids obtained by replacing each `?` in $S$ with `1`, `2`, or `3`, the following six grids satisfy the condition.
Input #2
2 3
123
3?1
Output #2
0
None of the grids obtained by replacing `?` satisfies the condition.
Input #3
8 8
3?1?????
???1????
??????2?
????????
????????
????13??
??13?1??
????????
Output #3
779135038
题目信息

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