問題一覧 > 通常問題

No.2837 Flip Triomino

レベル : / AI推定難易度 : 1725 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 88
作問者 : milkcoffee / テスター : suo ygussany
お気に入りにしたユーザー ProblemId : 11206 / 自分の提出
問題文最終更新日: 2024-08-03 20:23:50
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 440 (順位表) の他の問題:

Problem Statement

For a grid with $N$ rows and $M$ columns, the cell in the $i$-th row and $j$-th column is called $(i,j)$.

A colored grid is defined to be a good grid if all of its cells can be made white by repeating the following operation.

  • Choose $3$ cells enclosed by one of the following $4$ types of shapes (rotation is not allowed), and flip their colors.

    Formally, perform one of the following operations.
    • Choose integers $x,y \ (1 \leq x \leq N-2, \ 1 \leq y \leq M)$ and flip the colors of the $3$ cells $(x,y),(x+1,y),(x+2,y)$.
    • Choose integers $x,y \ (1 \leq x \leq N, \ 1 \leq y \leq M-2)$ and flip the colors of the $3$ cells $(x,y),(x,y+1),(x,y+2)$.
    • Choose integers $x,y \ (1 \leq x \leq N-1, \ 1 \leq y \leq M-1)$ and flip the colors of the $3$ cells $(x,y),(x+1,y),(x+1,y+1)$.
    • Choose integers $x,y \ (1 \leq x \leq N-1, \ 1 \leq y \leq M-1)$ and flip the colors of the $3$ cells $(x,y),(x,y+1),(x+1,y+1)$.

You are given a grid with $N$ rows and $M$ columns. Each cell of the given grid is either painted white or black, or not painted.

If $S_{i,j}$ is W, B, then $(i,j)$ is a cell painted white, black, respectively; if it is ?, it is an unpainted cell.

Find the number, modulo $998244353$, of ways to paint each unpainted cell of the given grid white or black such that the resulting grid is a good grid.

Input

$N$ $M$
$S_{1,1}S_{1,2}\ldots S_{1,M}$
$\vdots$
$S_{N,1}S_{N,2}\ldots S_{N,M}$

  • $3 \leq N,M \leq 500$
  • $N,M$ are integers
  • $S_{i,j}$ is one of W,B,?

Output

Output the answer as an integer.

Sample

Sample 1
Input
3 4
??BW
WBBW
WWWW
Output
1

The $2$ cells $(1,1),(1,2)$ are unpainted, so there are $2^2=4$ ways to paint in total.

If $(1,1)$ is painted black and $(1,2)$ is painted white, all cells can be made white with $2$ operations as shown in the figure below, so this is a good grid.

This $1$ way is the only painting that results in a good grid.

Sample 2
Input
3 3
WWW
WBW
BBW
Output
0

The given grid is not a good grid. Note that the shapes used to flip colors cannot be rotated.

Sample 3
Input
12 30
WW?W?BW??B??WBWBW?WWWWB?WBWWWW
BBB?WBBWWBBWW?WW?BWBWW?WBWW?WW
WBBBW?BW?WB?BWBWWWBBBWWWWB??WB
WW?WWBWWWWB?B?BBBWB?BBB?BB?W??
B?BB?WWBWWBW?BWBBBWWBBBB??B??B
WWBWWBWBWWW??W?WBBBWWWWW?WW?WW
WWWBB?B?BWB?WBWBW?W?BBBWB?WBBW
??BBWWBWW?WWBBBW?WWBWW?BWBBBWW
WBW?WW?B??BW?BWWBBBW?WWWWB??BB
W?BW?BWWBB?BW??BWWWWBB??BW?BWB
?WWW?WB?WWBBBWWBBBWWBW?BBWW?BB
?WWWBWBBWWWBWWWBBWWWB?WW?BWBWB
Output
511566473

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。