#P9522. [JOIST 2022] 错误拼写 / Misspelling
[JOIST 2022] 错误拼写 / Misspelling
Background
JOISC2022 D1T3
Problem Description
Once upon a time, President K had a string of length , consisting only of lowercase letters. However, he forgot it.
He also has a dictionary that contains various kinds of misspellings. He once read that dictionary, and now he is sure that satisfies the following condition:
- Let be the string obtained by deleting the -th character of and concatenating the remaining parts. For every , it holds that .
Here, means that is equal to , or is lexicographically smaller than .
Write a program that, given the information above about , outputs the number of possible strings , modulo .
Input Format
The first line contains two positive integers , representing the length of and the number of constraints.
The following lines: the -th line contains two positive integers , representing one constraint.
Output Format
Output one line containing one non-negative integer, the number of possible strings modulo .
3 2
1 3
3 2
5876
5 6
1 2
1 5
2 4
5 4
5 3
4 3
656981
10 9
3 6
4 6
6 7
7 9
10 8
9 8
8 5
5 2
5 1
206289833
7 6
1 3
3 4
4 6
6 5
5 7
7 2
7125651
5 4
2 4
4 3
3 5
5 1
61451
Hint
Sample Explanation #1.
For example, if , then $T_1 = \texttt{ab}, T_2 = \texttt{bb}, T_3 = \texttt{ba}$. It satisfies and . Therefore, this is valid.
It can be proven that there are valid strings in total. Hence, the output is .
On the other hand, if , then $T_1 = \texttt{ab}, T_2 = \texttt{ab}, T_3 = \texttt{aa}$. It does not satisfy . Therefore, this is invalid.
This sample satisfies the constraints of all subtasks.
Sample Explanation #2.
This sample satisfies the constraints of subtasks .
Sample Explanation #3.
The result before taking modulo is , so the output is .
This sample satisfies the constraints of subtasks .
Sample Explanation #4.
This sample satisfies the constraints of all subtasks.
Sample Explanation #5.
This sample satisfies the constraints of all subtasks.
Constraints.
For all testdata, it holds that:
- .
- .
- .
- .
- .
The detailed additional constraints and scores for subtasks are shown in the table below:
| Subtask ID | Additional Constraints | Score |
|---|---|---|
| There exists a permutation of such that | ||
| No additional constraints |
Translated by ChatGPT 5