#abc295h. Ex - E or m

Ex - E or m

Score : 600600 points

问题描述

我们有一个 NN 行和 MM 列的网格 AA。最初,每个格子上都写有数字 00

  • 对于满足 1iN1 \le i \le N 的每个整数 ii,在第 ii 行中,将左侧零个或多个格子中的数字变为 11
  • 对于满足 1jM1 \le j \le M 的每个整数 jj,在第 jj 列中,将顶部零个或多个格子中的数字变为 11

SS 为通过上述方式可以获得的所有网格集合。

给定一个由 01? 组成的 NN 行和 MM 列的网格 XX

其中包含 qq?,通过将每个 ? 替换为 01,可以得到 2q2^q 个不同的网格。请问,在这些网格中有多少个属于集合 SS

由于这个计数可能非常大,请计算它对 998244353998244353 取模的结果。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

We have a grid AA with NN rows and MM columns. Initially, 00 is written on every square.
Let us perform the following operation.

  • For each integer ii such that 1iN1 \le i \le N, in the ii-th row, turn the digits in zero or more leftmost squares into 11.
  • For each integer jj such that 1jM1 \le j \le M, in the jj-th column, turn the digits in zero or more topmost squares into 11.

Let SS be the set of grids that can be obtained in this way.

You are given a grid XX with NN rows and MM columns consisting of 0, 1, and ?.
There are 2q2^q grids that can be obtained by replacing each ? with 0 or 1, where qq is the number of ? in XX. How many of them are in SS?
This count can be enormous, so find it modulo 998244353998244353.

Constraints

  • NN and MM are integers.
  • 1N,M181 \le N,M \le 18
  • XX is a grid with NN rows and MM columns consisting of 0, 1, and ?.

Input

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

NN MM

X1,1X1,2X1,MX_{1,1} X_{1,2} \dots X_{1,M}

X2,1X2,2X2,MX_{2,1} X_{2,2} \dots X_{2,M}

\vdots

XN,1XN,2XN,MX_{N,1} X_{N,2} \dots X_{N,M}

Output

Print an integer representing the answer.

Sample Input 1

2 3
0?1
?1?

Sample Output 1

6

The following six grids are in SS.

011  011  001
010  011  110

001  011  011
111  110  111

Sample Input 2

5 3
101
010
101
010
101

Sample Output 2

0

XX may have no ?, and the answer may be 00.

Sample Input 3

18 18
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????

Sample Output 3

462237431

Be sure to find the count modulo 998244353998244353.

update @ 2024/3/10 12:17:21