#P17412. 【MX-X31-T6】「FAOI-R14」数据生成器(加强版)

    ID: 19954 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 显示难度NOI/NOI+/CTS 上传者: 标签>网络流O2优化图论建模快速莫比乌斯变换 FMT状压 DP梦熊比赛

【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 n,mn, m.

Problem Description

Little A created a problem for the Mengxiong Weekly Contest:

Given two integer sequences a1,a2,…,ana_1, a_2, \ldots, a_n and b1,b2,…,bmb_1, b_2, \ldots, b_m, and an n×mn \times m matrix cc whose elements all belong to {0,1,2}\{0,1,2\}.

For every 22 in cc, you need to replace it with 00 or 11; the original 00 and 11 in the matrix remain unchanged. After replacement, you obtain a 0101 matrix dd. The matrix dd must satisfy:

  • For all i∈[1,n]i \in [1,n], ∑j=1mdi,j≥ai\sum_{j=1}^m d_{i,j} \ge a_i;
  • For all j∈[1,m]j \in [1,m], ∑i=1ndi,j≥bj\sum_{i=1}^n d_{i,j} \ge b_j;

Among all matrices dd that satisfy the conditions above, you need to minimize the number of 11 in the matrix.

If a matrix dd satisfies the conditions above, and there does not exist another matrix that also satisfies the conditions above and has no more 11 than it, then dd 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 n,mn, m, and an n×mn \times m set matrix SS. For all i∈[1,n]i \in [1,n] and j∈[1,m]j \in [1,m], we have Si,j⊆{0,1,2}S_{i,j} \subseteq \{0,1,2\} and Si,j≠∅S_{i,j} \ne \varnothing.

Then, Little A independently generates one piece of data (a,b,c)(a,b,c) in the following way:

  • For all i∈[1,n]i \in [1,n], choose aia_i uniformly at random from the integer set {0,1,…,m}\{0,1,\ldots,m\}.
  • For all j∈[1,m]j \in [1,m], choose bjb_j uniformly at random from the integer set {0,1,…,n}\{0,1,\ldots,n\}.
  • For all i∈[1,n]i \in [1,n], j∈[1,m]j \in [1,m], choose ci,jc_{i,j} uniformly at random from the set Si,jS_{i,j}.

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 n,mn, m, the set matrix SS, and a fixed n×mn \times m 0101 matrix hh. You need to compute, among all possible data (a,b,c)(a,b,c), how many pieces of data make hh the unique optimal solution of the original problem. Output the answer modulo 998244353998244353.

Input Format

The first line contains two positive integers n,mn, m, representing the matrix size.

The next nn lines each contain a string of length mm. Let the decimal integer represented by the jj-th character in the ii-th line be xx, where 1≤x≤71 \le x \le 7. For each y∈{0,1,2}y \in \{0,1,2\}, y∈Si,jy \in S_{i,j} if and only if the yy-th bit (from low to high) in the binary representation of xx is 11.

The next nn lines describe the matrix hh. Each line contains a 01 string of length mm. The jj-th character in the ii-th line represents hi,jh_{i,j}.

Output Format

Output one line containing a non-negative integer, representing the result modulo 998244353998244353. It is guaranteed that the answer before taking modulo is not 00.

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 cc.

  • If c1,2=1c_{1,2} = 1, then there are 1212 choices of (a,b)(a,b) that make hh the unique optimal solution:
    • a=[0,2]a=[0,2], b=[0,0]b=[0,0];
    • a=[0,2]a=[0,2], b=[0,1]b=[0,1];
    • a=[0,2]a=[0,2], b=[0,2]b=[0,2];
    • a=[0,2]a=[0,2], b=[1,0]b=[1,0];
    • a=[0,2]a=[0,2], b=[1,1]b=[1,1];
    • a=[0,2]a=[0,2], b=[1,2]b=[1,2];
    • a=[1,2]a=[1,2], b=[0,0]b=[0,0];
    • a=[1,2]a=[1,2], b=[0,1]b=[0,1];
    • a=[1,2]a=[1,2], b=[0,2]b=[0,2];
    • a=[1,2]a=[1,2], b=[1,0]b=[1,0];
    • a=[1,2]a=[1,2], b=[1,1]b=[1,1];
    • a=[1,2]a=[1,2], b=[1,2]b=[1,2].
  • If c1,2=2c_{1,2} = 2, then there are 44 choices of (a,b)(a,b) that make hh the unique optimal solution:
    • a=[0,2]a=[0,2], b=[0,2]b=[0,2];
    • a=[0,2]a=[0,2], b=[1,2]b=[1,2];
    • a=[1,2]a=[1,2], b=[0,2]b=[0,2];
    • a=[1,2]a=[1,2], b=[1,2]b=[1,2].

Therefore, there are 12+4=1612+4=16 pieces of data that satisfy the condition.

Constraints

For all testdata:

  • 1≤n,m≤101 \le n, m \le 10;
  • For all 1≤i≤n1 \le i \le n, 1≤j≤n1 \le j \le n, Si,j⊆{0,1,2}S_{i,j} \subseteq \{0,1,2\} and Si,j≠∅S_{i,j} \ne \varnothing.
  • For all 1≤i≤n1 \le i \le n, 1≤j≤n1 \le j \le n, hi,j∈{0,1}h_{i,j} \in \{0,1\}.

Translated by ChatGPT 5