Yeoksam Station
Time limit2sMemory limit1024 MB
Count the distinct substrings of S that contain a palindrome of length at least K.
- Level
Hard8 of 10
- Topics
- String, String matching, Sorting
- Solved
- No attempts yet
Problem
This problem is fun. It feels like my favorite string quiz. You are given a string of length and a positive integer . A string is called a "Yeowoo string" if it has a palindrome of length at least as a substring. How many distinct substrings of are Yeowoo strings?
A palindrome reads the same forwards and backwards, such as "기러기", "토마토", "스위스", "인도인", "별똥별", and "우영우". A substring is a contiguous part of a string that is not empty.
For example, when is "banana" and , the distinct substrings of are the following.
- "a", "an", "ana", "anan", "anana"
- "b", "ba", "ban", "bana", "banan", "banana"
- "n", "na", "nan", "nana"
Of these, the Yeowoo strings are the following 8.
- "ana", "anan", "anana"
- "bana", "banan", "banana"
- "nan", "nana"
Input
The first line contains and , separated by a space.
The second line contains the string , which consists only of lowercase English letters.
Output
Print the number of distinct substrings of that are Yeowoo strings.
Hint
If you only focus on counting, you cannot solve this problem. Look at the core idea.