#P7969. [KSN2021] Self Defence
[KSN2021] Self Defence
Problem Description
Define the weight of a string as the number of its substrings that have length and contain only one distinct character.
For example, for the string ABBB, when , its weight is .
Given a string of length , where each character is one of ?, A, and B, you need to find how many strings can be obtained with weight after replacing each ? with A or B.
Output the answer modulo .
Input Format
The first line contains three integers .
The second line contains a string of length .
Output Format
Output one integer representing the answer.
5 4 1
?????
4
5 2 2
A????
6
5 3 4
AAAAA
0
Hint
Sample Explanation
For the first sample, the following are all valid strings:
AAAAB
ABBBB
BAAAA
BBBBA
For the second sample, the following are all valid strings:
AAABA
AABAA
AABBA
ABAAA
ABBAA
ABBBA
Constraints
This problem uses bundled testdata.
- Subtask 1 (5 points): There is only one test case, satisfying , , , .
- Subtask 2 (9 points): .
- Subtask 3 (11 points): .
- Subtask 4 (6 points): , .
- Subtask 5 (9 points): .
- Subtask 6 (8 points): .
- Subtask 7 (27 points): contains only
?. - Subtask 8 (25 points): No special restrictions.
For all test cases, , , .
Translated by ChatGPT 5