#P17412. 【MX-X31-T6】「FAOI-R14」数据生成器(加强版)
【MX-X31-T6】「FAOI-R14」数据生成器(加强版)
Background
This problem is an enhanced version of P17410 [MX-X31-T6] "FAOI-R14" Data Generator. The only difference is the range of .
Problem Description
Little A created a problem for the Mengxiong Weekly Contest:
Given two integer sequences and , and an matrix whose elements all belong to .
For every in , you need to replace it with or ; the original and in the matrix remain unchanged. After replacement, you obtain a matrix . The matrix must satisfy:
- For all , ;
- For all , ;
Among all matrices that satisfy the conditions above, you need to minimize the number of in the matrix.
If a matrix satisfies the conditions above, and there does not exist another matrix that also satisfies the conditions above and has no more than it, then is called the unique optimal solution of the original problem.
Little A is a "cold-hearted" problem setter and loves to handcraft testdata. Little A first chooses positive integers , and an set matrix . For all and , we have and .
Then, Little A independently generates one piece of data in the following way:
- For all , choose uniformly at random from the integer set .
- For all , choose uniformly at random from the integer set .
- For all , , choose uniformly at random from the set .
Therefore, in total there can be $(m+1)^n (n+1)^m \prod_{i=1}^{n} \prod_{j=1}^{m} |S_{i,j}|$ different pieces of data.
Obviously, the original problem may have multiple optimal solutions. As a "cold-hearted" problem setter, Little A naturally does not want to write an SPJ. However, considering that if a Mengxiong Weekly Contest problem goes wrong he will get his salary deducted, Little A still wants to know the probability that the judging can work correctly without an SPJ.
Little A gives you his , the set matrix , and a fixed matrix . You need to compute, among all possible data , how many pieces of data make the unique optimal solution of the original problem. Output the answer modulo .
Input Format
The first line contains two positive integers , representing the matrix size.
The next lines each contain a string of length . Let the decimal integer represented by the -th character in the -th line be , where . For each , if and only if the -th bit (from low to high) in the binary representation of is .
The next lines describe the matrix . Each line contains a 01 string of length . The -th character in the -th line represents .
Output Format
Output one line containing a non-negative integer, representing the result modulo . It is guaranteed that the answer before taking modulo is not .
2 2
46
44
01
11
16
3 3
124
224
412
011
110
101
135
4 5
44646
75547
64745
75445
01101
10000
10101
00110
4064
8 8
66677655
77554747
73366765
21773775
73766676
73777775
77475565
56751776
11100100
10001010
11101110
10001010
01100111
10010010
10010010
01100111
46434700
Hint
Sample #1 Explanation
There are two possible matrices .
- If , then there are choices of that make the unique optimal solution:
- , ;
- , ;
- , ;
- , ;
- , ;
- , ;
- , ;
- , ;
- , ;
- , ;
- , ;
- , .
- If , then there are choices of that make the unique optimal solution:
- , ;
- , ;
- , ;
- , .
Therefore, there are pieces of data that satisfy the condition.
Constraints
For all testdata:
- ;
- For all , , and .
- For all , , .
Translated by ChatGPT 5