#P10101. [ROIR 2023] 一个普通的字符串问题 (Day 2)
[ROIR 2023] 一个普通的字符串问题 (Day 2)
Background
Translated from ROIR 2023 D2T4。
If for any string of length , the number of occurrences of in string is the same as the number of occurrences of in string , then the two strings and are called equivalent strings. Therefore, the strings aaaba, abaaa, and baaab are equivalent to each other (the substring aa appears twice, ab appears once, ba appears once, and bb does not appear as a substring), while cff and ccf are not equivalent. A string is equivalent to itself.
Problem Description
In this problem, you are given strings consisting of the characters a, b, and c. For each string, you need to compute the number of non-empty strings consisting of the characters a, b, and c that are equivalent to it. Since this number can be very large, output it modulo .
Input Format
The first line contains an integer , which indicates the index of the current subtask. In the sample, . This problem also provides an additional Subtask 0 with score to store the sample testdata.
The second line contains an integer .
The next lines each contain a string.
Output Format
For each string, output one line with one integer representing the answer, modulo .
0
4
abaa
abca
ccbca
bacc
3
3
2
1
Hint
Sample explanation:
- The string
abaais equivalent toabaa,aaba,baab; - The string
abcais equivalent toabca,bcab,cabc; - The string
ccbcais equivalent toccbcaandcbcca; - The string
baccis only equivalent tobacc.
This problem uses bundled tests.
Let be the length of the -th input string, be the sum of lengths of all strings, and be the maximum (not modulo) answer among all queries.
Constraints
| Subtask ID | Score | Special Property |
|---|---|---|
| The input testdata is the same as the sample | ||
contains no c |
||
a and c are not adjacent in |
||
| None | ||
For of the testdata, and .
Translated by ChatGPT 5