← Home
write a go solution for Description:
There is a grid with r rows and c columns, where the square on the i-th row and j-th column has an integer a_i,j written on it. Initially, all elements are set to 0. We are allowed to do the following operation:

- Choose indices 1<=i<=r and 1<=j<=c, then replace all values on the same row or column as (i,j) with the value xor 1. In other words, for all a_x,y where x=i or y=j or both, replace a_x,y with a_x,y xor 1.

You want to form grid b by doing the above operations a finite number of times. However, some elements of b are missing and are replaced with '?' instead.

Let k be the number of '?' characters. Among all the 2^k ways of filling up the grid b by replacing each '?' with '0' or '1', count the number of grids, that can be formed by doing the above operation a finite number of times, starting from the grid filled with 0. As this number can be large, output it modulo 998244353.

Input Format:
The first line contains two integers r and c (1<=r,c<=2000)  — the number of rows and columns of the grid respectively.

The i-th of the next r lines contain c characters b_i,1,b_i,2,ldots,b_i,c (b_i,jin0,1,?).

Output Format:
Print a single integer representing the number of ways to fill up grid b modulo 998244353.

Note:
In the first test case, the only way to fill in the texttt?s is to fill it in as such:

010111010

This can be accomplished by doing a single operation by choosing (i,j)=(2,2).

In the second test case, it can be shown that there is no sequence of operations that can produce that grid.. Output only the code with no comments, explanation, or additional text.