Computational Biology
Time limit5sMemory limit128 MB
For each query length m, find a length-m word whose every cyclic rotation appears in s, maximizing the total count of those rotations in s.
- Level
Hard9 of 10
- Topics
- String, Sorting, String matching, Sliding window
- Solved
- No attempts yet
Problem
Byteasar works at the Byteland Centre for Computational Biology. He has just received a long sequence of genomes and wants to find the cyclic fragments that occur most often in it.
The sequence is a word over capital English letters. A cyclic rotation of a word is obtained by moving its last letter to the front, possibly several times in a row. For example, ABAABA has three distinct cyclic rotations: ABAABA, BAABAA, and AABAAB. A word is a subword of a word if occurs in as a block of consecutive letters.
A word is a cyclic fragment of if every cyclic rotation of is a subword of . For such a , its number of cyclic occurrences in is the total number of occurrences in of the distinct cyclic rotations of .
For each query length , report the largest number of cyclic occurrences achievable by a cyclic fragment of of length . If has no cyclic fragment of length , the answer is 0.
Input
The first line contains two integers and (, ): the length of the genome sequence and the number of queries. The second line contains the word , made of capital letters of the English alphabet. Each of the next lines contains one integer (), the length of the cyclic fragments to consider in that query.
Output
Output lines. The -th line must contain a single integer: the maximum number of cyclic occurrences over all cyclic fragments of of length (or 0 if none exists).
Note
Take AABAABACDABAABAA. For length 6, the cyclic fragment AABAAB has three distinct cyclic rotations, and together they occur 4 times in : once as AABAAB, twice as ABAABA, and once as BAABAA. No length-6 cyclic fragment does better, so the answer is 4. For length 3, the cyclic fragment AAB occurs 10 times in total across its rotations AAB, ABA, and BAA, which is the maximum.