#P71. [CSP-S 2019 Day 2] Guest Treating
[CSP-S 2019 Day 2] Guest Treating
Person in Charge
Problem Description
Emiya is a high school student who is good at cooking. He has mastered kinds of cooking methods and can cook using kinds of main ingredients. For the sake of convenience, we number the cooking methods from to and the main ingredients from to .
Each dish Emiya makes uses exactly one cooking method and exactly one main ingredient. More specifically, Emiya can make different dishes that use cooking method and main ingredient (, ), which means Emiya can make a total of $\sum\limits_{i=1}^{n} \sum\limits_{j=1}^{m} a_{i,j}$ different dishes.
Today, Emiya is going to prepare a meal to entertain his good friends Yazid and Rin. However, the three of them have different requirements for the combination of dishes. More specifically, for a combination plan containing dishes:
- Emiya will not let everyone go hungry, so he will make at least one dish, i.e., .
- Rin wants to taste dishes made with different cooking methods, so she requires that each dish uses a distinct cooking method.
- Yazid does not want to taste too many dishes made with the same ingredient, so he requires that each main ingredient is used in at most half of the dishes (i.e., dishes).
Here, is the floor function, representing the largest integer not exceeding .
These requirements do not trouble Emiya, but he wants to know how many different combination plans meet all the requirements. Two plans are different if and only if there is at least one dish that appears in one plan but not in the other.
Emiya has come to you for help. Please calculate the number of valid combination plans modulo the prime number and tell him the result.
Input Format
The first line contains two integers and separated by a single space.
Lines 2 to each contain integers separated by a single space, where the numbers in line are in sequence.
Output Format
Output a single integer on one line, representing the number of valid plans modulo .
Samples
2 3
1 0 1
0 1 1
3
3 3
1 2 3
4 5 0
6 0 0
190
Sample 1 Explanation
In this sample, for each pair , Emiya can make at most one dish, so we directly describe a dish by giving the numbers of the cooking method and main ingredient.
The valid plans include:
- Making one dish with cooking method and main ingredient , and one dish with cooking method and main ingredient .
- Making one dish with cooking method and main ingredient , and one dish with cooking method and main ingredient .
- Making one dish with cooking method and main ingredient , and one dish with cooking method and main ingredient .
Thus, the output result is . Note that all plans containing only one dish are invalid, because the only main ingredient is used in more than half of the dishes, which does not meet Yazid's requirement.
Sample 2 Explanation
Emiya must make at least dishes.
The number of valid plans with dishes is .
The number of valid plans with dishes is .
Therefore, the total number of valid plans is .
Sample 3
See meal/meal3.in and meal/meal3.ans in the contestant's directory.
Data Range
| Test Case ID | Test Case ID | ||||||
|---|---|---|---|---|---|---|---|
For of the data: , , .