Hardcore String Counting
Time limit8sMemory limit2048 MB
Count strings of length m over 26 letters where s first appears as a substring at the very end, modulo 998244353, with n up to 1e5 and m up to 1e9.
- Level
Hard9 of 10
- Topics
- String matching, Dynamic programming, Combinatorics
- Solved
- No attempts yet
Problem
You are given a non-empty string of lowercase English letters. A string of lowercase English letters is good if every proper prefix of does not contain as a substring, but itself does.
Find the number of good strings of length . Because this number can be very large, output it modulo the prime number .
Input
The first line contains two integers , the length of , and , the length of the strings to count (, ). The second line contains the string , which consists of lowercase English letters.
Output
Output a single nonnegative integer: the number of good strings of length modulo .