#abc268g. G - Random Student ID
G - Random Student ID
Score : points
问题描述
Takahashi 小学有 名新学生。对于 ,第 名新学生的姓名是 (由小写英文字母组成的字符串)。这 名新学生的姓名各不相同。
这 名学生将根据他们的姓名的升序字典顺序被分配学号 。但是,我们不使用普通的字母表顺序(其中 a
是最小的,z
是最大的),而是采用以下顺序:
- 首先,高桥校长从长度为 的字符串
abcdefghijklmnopqrstuvwxyz
的 种排列中,随机均匀选择一个字符串 。 - 在 中出现较早的小写英文字母被认为较小。
对于 名学生中的每一位,计算并求出(见注释)所分配学号的期望值对 取模的结果。
什么是字典顺序?
字符串 被认为在字典序上小于字符串 ,当且仅当以下 1. 和 2. 中的一个条件成立。这里, 和 分别表示字符串 和 的长度。
- 并且 。
- 存在一个整数 满足以下两个条件:
- 字符比 字符更小。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
Takahashi Elementary School has new students. For , the name of the -th new student is (which is a string consisting of lowercase English letters). The names of the new students are distinct.
The students will be assigned a student ID in ascending lexicographical order of their names. However, instead of the ordinary order of lowercase English letters where a
is the minimum and z
is the maximum, we use the following order:
- First, Principal Takahashi chooses a string from the permutations of the string
abcdefghijklmnopqrstuvwxyz
of length , uniformly at random. - The lowercase English characters that occur earlier in are considered smaller.
For each of the students, find the expected value, modulo , of the student ID assigned (see Notes).
What is the lexicographical order?
A string is said to be lexicographically smaller than a string if one of the following 1. and 2. holds. Here, and denote the lengths of and , respectively.
- and .
- There exists an integer satisfying the following two conditions:
- is a smaller character than .
Notes
We can prove that the sought expected value is always a rational number. Moreover, under the Constraints of this problem, when the value is represented as by two coprime integers and , we can prove that there is a unique integer such that and . Find such .
Constraints
- is an integer.
- is a string of length at least consisting of lowercase English letters.
- The sum of lengths of the given strings is at most .
Input
Input is given from Standard Input in the following format:
Output
Print lines. For each , the -th line should contain the expected value, modulo , of the student ID assigned to Student .
Sample Input 1
3
a
aa
ab
Sample Output 1
1
499122179
499122179
The expected value of the student ID assigned to Student is ; the expected values of the student ID assigned to Student and are .
Note that the answer should be printed modulo . For example, the sought expected value for Student and is , and we have , so should be printed.
Sample Input 2
3
a
aa
aaa
Sample Output 2
1
2
3
update @ 2024/3/10 11:20:00