#P5664. Delicious Combination
Delicious Combination
Delicious Combination
High‐school student Emiya is an excellent cook. He knows \( n \) different cooking methods (numbered from \( 1 \) to \( n \)) and uses \( m \) different main ingredients (numbered from \( 1 \) to \( m \)) in his dishes. For each pair \( (i,j) \) with \( 1 \le i \le n \) and \( 1 \le j \le m \), Emiya can cook \( a_{i,j} \) distinct dishes using cooking method \( i \) and main ingredient \( j \). In other words, he has a total of \( \sum_{i=1}^{n} \sum_{j=1}^{m} a_{i,j} \) distinct dishes at his disposal.
Today, he is preparing a feast for his two friends, Yazid and Rin. However, each friend has specific demands regarding the combination of dishes in the meal. Suppose Emiya chooses a combination of \( k \) dishes (with \( k \ge 1 \)). The requirements are as follows:
- Emiya must prepare at least one dish, i.e. \( k \ge 1 \).
- Rin wants to taste dishes prepared by different cooking methods; hence all chosen dishes must use distinct cooking methods.
- Yazid does not want too many dishes made from the same main ingredient. In particular, for every main ingredient, its count in the chosen dishes must be at most \( \lfloor \frac{k}{2} \rfloor \) (where \( \lfloor x \rfloor \) denotes the floor function, the greatest integer not exceeding \( x \)).
Two combinations are considered different if there is at least one dish that appears in one combination and not in the other. Emiya wants to know the total number of different valid combinations. Since the answer can be huge, output it modulo 998244353.
inputFormat
The first line contains two integers \( n \) and \( m \) separated by a space.
Then follow \( n \) lines, each containing \( m \) integers. The \( j \)-th number in the \( i \)-th line denotes \( a_{i,j} \) (\( 1 \le i \le n, 1 \le j \le m \)).
It is guaranteed that the input meets the problem constraints.
outputFormat
Output a single integer: the total number of valid dish combinations modulo 998244353.
sample
2 2
1 1
1 1
2