Longest Common Substring
Time limit5sMemory limit2048 MB
Count the pairs of binary strings s (length n) and t (length m) that have w as one of their longest common substrings, modulo 998244353.
- Level
Medium7 of 10
- Topics
- Dynamic programming, String matching, String
- Solved
- No attempts yet
Statement
Lisa wrote a program to solve the Longest Common Substring problem. She then used the program to find, for some two strings and consisting of characters '0' and '1', the longest string that is a substring of both and . If there were multiple such longest strings, she found an arbitrary one.
The length of that Lisa found was very small. It is at most 3.
Lisa remembers (the length of ), (the length of ), and , but she does not remember the strings and themselves. Now she wonders how many pairs of strings and exist such that they have lengths and , respectively, consist of characters '0' and '1', and have as one of their longest common substrings.
Help Lisa and find this number of pairs modulo . Note that if and , pairs and are considered distinct.
Input
The first line contains three integers , , and , denoting the lengths of the strings , , and (; ).
The second line contains the string of length consisting of characters '0' and '1'.
Output
Print the number of pairs of strings that have as one of their longest common substrings, modulo .
Hint
Note that a string is a substring of a string if can be obtained from by deleting zero or more characters from the beginning and zero or more characters from the end.
In the first test, all pairs of strings satisfying the conditions are ("01", "10"), ("01", "11"), ("10", "01"), ("10", "11"), ("11", "01"), and ("11", "10").