#P14476. 矩阵绘画
矩阵绘画
Problem Description
Elfin likes painting. One day, she started studying how to paint matrices.
More specifically, Elfin wants to paint an matrix. She starts from an all-zero matrix, and each time she can choose one row or one column to paint. If she chooses row , she adds to all entries in columns to of that row. If she chooses column , she adds to all entries in rows to of that column. She will not paint any cell more than once, because then the value in that cell would become greater than . Here, and are two sequences of length .
Elfin also has an draft matrix, whose entries may be , , or the character ?. If a cell in the draft matrix is or , then the corresponding cell in the matrix she paints must be that value. If a cell is ?, then there is no restriction on that cell.
Now Elfin wants to know how many different matrices she can paint. Two matrices are considered different if and only if there exists at least one cell where their values differ. Since the answer may be very large, output it modulo .
Input Format
Note: Due to Luogu's judging limitations, when submitting this problem on Luogu, please use standard input/output. Do not use file input/output.
The first line contains a positive integer .
The next line contains non-negative integers, representing .
The next line contains non-negative integers, representing .
The next lines each contain a string of length , representing the given draft matrix.
Output Format
Output one integer, the answer.
3
1 2 3
1 2 3
?11
???
?0?
2
1
0
0
1
0
Hint
Sample Explanation 1
There are possible matrices:
111 011
011 011
001 001
Sample Explanation 2
No matrix satisfies the requirements.
Constraints
All testdata satisfy: , , and each element in the draft matrix .
::cute-table{tuack}
| Test Point ID | Special Property | |
|---|---|---|
| — | ||
| — |
For each group of test points, the first two test points satisfy: the given matrix contains only question marks.
Translated by ChatGPT 5