#P11749. 「TPOI-1C」Standard Problem.
「TPOI-1C」Standard Problem.
Description
As a contest reviewer for a well-known CP platform, you often receive standard problem submissions.
Having overused replies like "quite standard" and "somewhat standard", you decide to try something new.
First, you write your review (a lowercase English string). To emphasize how standard the problem is, you concatenate times to form the final reply .
The submitter defines the weirdness of a reply as the number of palindromic substrings in it. Your task is to compute the weirdness of modulo .
Formally, given string and integer , find the number of distinct palindromic substrings (counted by position) in (the concatenation of copies of ), modulo .
Input Format
This problem contains multiple test cases.
The first line contains an integer indicating the number of test cases.
For each test case:
- The first line contains two integers representing the string length and concatenation count.
- The second line contains a lowercase English string of length .
The sum of across all test cases in a single input does not exceed .
Output Format
For each test case, output one integer representing the answer modulo .
3
4 2
abab
1 1
a
30 1
abaababaababaababaababaababaab
20
1
128
Hint
For the first sample input, contains 20 palindromic substrings.
For the third sample input, the resulting string is .
Constraints
This problem uses bundled tests. You must pass all test cases in a subtask to receive points.
Subtask 1 contains samples and is worth 0 points.
| Subtask | Points | ||
|---|---|---|---|
| 2 | 5 | 2 | |
| 3 | 30 | ||
| 4 | 2000 | ||
| 5 | 35 | ||
- Subtask 3 guarantees .
- Subtask 4 guarantees .
Translated by DeepSeek R1
京公网安备 11011102002149号