odd doctor 已更新

# CRB and Substrings

Time Limit
3s
Memory Limit
131072KB
Judge Program
Standard
Ratio(Solve/Submit)
100.00%(1/1)
Description:

Value of a string is defined as the number of distinct substrings of it.
For example, value of “ab” is 3(“a”, “b”, “ab”), and value of “xyx” is 5(“x”, “y”, “xy”, “yx”, “xyx”).
Now CRB has a string s.
For some integer k, CRB wants to know k-length substring of s which has maximum value. But it seems not so easy. Can you help him?

Input:

There are multiple test cases.
The first line contains a string s. The next line contains an integer Q denoting the number of queries. Each of the next Q lines contains a single integer k.
1 ≤ |s| ≤ 105
s consists only of lowercase English letters.
1 ≤ Q ≤ 10
1 ≤ k ≤ |s|

Output:

For each query k, output the string whose value is maximum among all k-length substrings of s, followed by its value.
If multiple substrings have same maximum value, output the lexicographically smallest one.

Sample Input:
baa
2
2
1
Sample Output:
ba 3
a 1
Hint:

Query 1:2-length substrings are “ba” and “aa”.Value of “ba” is 3, and value of “aa” is 2.

Query 2:1-length substrings are “b” and “a”.Both have value 1, but “a” is lexicographically smaller.

Source:

2015 Multi-University Training Contest 10

Submit