atcoder#ABC295H. [ABC295Ex] E or m
[ABC295Ex] E or m
Score : points
Problem Statement
We have a grid with rows and columns. Initially, is written on every square. Let us perform the following operation.
- For each integer such that , in the -th row, turn the digits in zero or more leftmost squares into .
- For each integer such that , in the -th column, turn the digits in zero or more topmost squares into .
Let be the set of grids that can be obtained in this way.
You are given a grid with rows and columns consisting of 0
, 1
, and ?
.
There are grids that can be obtained by replacing each ?
with 0
or 1
, where is the number of ?
in . How many of them are in ?
This count can be enormous, so find it modulo .
Constraints
- and are integers.
- is a grid with rows and columns consisting of
0
,1
, and?
.
Input
The input is given from Standard Input in the following format:
Output
Print an integer representing the answer.
2 3
0?1
?1?
6
The following six grids are in .
011 011 001
010 011 110
001 011 011
111 110 111
5 3
101
010
101
010
101
0
may have no ?
, and the answer may be .
18 18
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
462237431
Be sure to find the count modulo .