Consistent Occurrences
Time limit4sMemory limit512 MB
Given a string s and many query strings, for each query find the largest set of non-overlapping occurrences of that query string in s.
- Level
Hard8 of 10
- Topics
- String, String matching, Greedy, Sorting
- Solved
- No attempts yet
Problem
A consistent set of occurrences of string in string is a set of occurrences of in such that no two occurrences intersect. In other words, no character position in belongs to two different occurrences.
You are given a string consisting of lowercase English letters, and queries. Each query contains a single string .
For each query, print the maximum size of a consistent set of occurrences of in .
Input
The first line contains two space-separated integers and : the length of string and the number of queries (, ).
The second line contains the string consisting of lowercase English letters.
Each of the next lines contains a single string consisting of lowercase English letters: the -th query (, where is the length of the string ).
It is guaranteed that the total length of all does not exceed characters.
Output
For each query , print one integer on a separate line: the maximum size of a consistent set of occurrences of in .