|
||||||||||
CRB and SubstringsTime Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 397 Accepted Submission(s): 33 Problem 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|$ ¡Ü $10^{5}$ $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
Sample Output
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. Author KUT£¨DPRK£© Source | ||||||||||
|