#P6453. [COCI 2008/2009 #4] PERIODNI
[COCI 2008/2009 #4] PERIODNI
Description
As shown in the figure, you are given a grid consisting of columns, and the bottoms of all columns are aligned.
You need to place identical numbers into it, but no two numbers may be in the same row or the same column.
For example, in the figure, placing b is invalid because the two b are in the same column. However, placing a is valid, because although the two a are on the same row, there is a gap between them, so it is not considered invalid.
Compute the total number of valid placements modulo .
Input Format
The first line contains two integers , representing the number of columns in the grid and the number of identical numbers to place.
The second line contains integers. The -th integer (from left to right) represents the height (number of levels) of the -th column.
Output Format
Output one integer on a single line, representing the number of valid placements modulo .
3 3
2 1 3
2
4 1
1 2 3 4
10
5 2
2 3 1 2 4
43
3 2
999999 999999 999999
990979013
Hint
Constraints
- For of the testdata, the input numbers are all less than .
- For of the testdata, the input numbers are all less than .
- For of the testdata, , and the column heights do not exceed .
Notes
This problem is translated from COCI2008-2009 CONTEST #4 T6 PERIODNI。
Input Format
The first line contains two integers , representing the number of columns in the grid and the number of identical numbers to place.
The second line contains integers. The -th integer (from left to right) represents the height (number of levels) of the -th column.
Output Format
Output one integer on a single line, representing the number of valid placements modulo .
Hint
Constraints
- For of the testdata, the input numbers are all less than .
- For of the testdata, the input numbers are all less than .
- For of the testdata, , and the column heights do not exceed .
Notes
This problem is translated from COCI2008-2009 CONTEST #4 T6 PERIODNI。
Translated by ChatGPT 5
京公网安备 11011102002149号