#P11487. 「Cfz Round 5」Gnirts 10
「Cfz Round 5」Gnirts 10
Description
Let's keep the problem statement simple.
- Given , and a binary string of length .
- For a binary string , define as the length of the longest prefix of that is a subsequence of .
- For every binary string that contains exactly s and s, compute the sum of . The answer should be modulo .
: Note that a subsequence does not need to be contiguous. In other words, is a subsequence of if and only if can be obtained by deleting characters from . Note that the empty string is always a subsequence of any string.
: The modulus is a prime number.
Input Format
The first line contains two integers .
The second line contains a binary string of length .
Output Format
Output a single integer, representing the result modulo .
2 1
000
3
5 5
0010111011
1391
Hint
Sample Explanation #1
The only possible sequence is the common sequence . Since there are exactly 3 different s (), the answer is .
Constraints
For all test cases, it is guaranteed that .
Subtasks are used in this task.
- Subtask 0 (13 points): .
- Subtask 1 (13 points): .
- Subtask 2 (34 points): .
- Subtask 3 (40 points): No further restrictions.
京公网安备 11011102002149号