시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
3.5 초 | 1024 MB | 42 | 21 | 19 | 47.500% |
Some time ago, President K had a string $S$ of length $N$ consisting of lower case characters. But, he forgot it. He had a dictionary which contains misspellings of several kinds, and he once took a look at the dictionary to check the misspellings of the string $S$. Now, he remembers that the following is true for the string $S$.
Here, $T_{A_j} ≤ T_{B_j}$ means either $T_{A_j}$ is equal to $T_{B_j}$, or $T_{A_j}$ is smaller than $T_{B_j}$ in the lexicographic order (alphabetical order).
Write a program which, given information on the string $S$ remembered by President K, calculates the number of strings $S$ modulo $1\,000\,000\,007$ which do not contradict given information.
Read the following data from the standard input. Given values are all integers.
$\begin{align*} & N \, M \\ & A_1 \, B_1 \\ & A_2 \, B_2 \\ & \vdots \\ & A_M\, B_M \end{align*}$
Write one line to the standard output. The output should contain the number of strings $S$ modulo $1\,000\,000\,007$ which do not contradict given information.
번호 | 배점 | 제한 |
---|---|---|
1 | 8 | $N ≤ 10$. |
2 | 20 | $N ≤ 200$. |
3 | 29 | $M = N - 1$. Moreover, there exists a permutation $P$ of $(1, 2, \dots , N)$ of length $N$ satisfying $A_j = P_j$ and $B_j = P_{j+1}$ ($1 ≤ j ≤ M$). |
4 | 32 | $N ≤ 20\,000$. |
5 | 11 | No additional constraints. |
3 2 1 3 3 2
5876
For example, if the string $S$ is bab
, we have $T_1 = $ab
, $T_2 = $bb
, $T_3 = $ba
. The relations $T_1 ≤ T_3$ and $T_3 ≤ T_2$ hold. This string does not contradict given information. In total, there are $5876$ strings $S$ which do not contradict given information. Therefore, output $5876$.
On the other hand, for example, if the strings $S$ is aab
, we have $T_1 = $ab
, $T_2 = $ab
, $T_3 = $aa
. The relation $T_1 ≤ T_3$ does not hold. Therefore, this string contradicts given information.
This sample input satisfies the constraints of all the subtasks.
5 6 1 2 1 5 2 4 5 4 5 3 4 3
656981
This sample input satisfies the constraints of Subtasks 1, 2, 4, 5.
10 9 3 6 4 6 6 7 7 9 10 8 9 8 8 5 5 2 5 1
206289833
The number of strings $S$ which do not contradict given information is $824\,206\,295\,601$. Therefore, output $206\,289\,833$, which is the remainder of $824\,206\,295\,601$ when divided by $1\,000\,000\,007$.
This sample input satisfies the constraints of Subtasks 1, 2, 4, 5.
7 6 1 3 3 4 4 6 6 5 5 7 7 2
7125651
This sample input satisfies the constraints of all the subtasks.
5 4 2 4 4 3 3 5 5 1
61451
This sample input satisfies the constraints of all the subtasks.