Not a subsequence
Time limit2sMemory limit256 MB
Given alphabet size k and string s, find the length of the shortest string over the alphabet that is not a subsequence of s and count such strings modulo 1e9+7.
- Level
Medium6 of 10
- Topics
- Greedy, String, Combinatorics
- Solved
- No attempts yet
Problem
In this problem, an alphabet of size means the first characters of the list below.
a, b, c, ..., z, A, B, C, ..., Z, 0, 1, ..., 9
Each test case gives its own , and only the alphabet of size is considered.
A string is a subsequence of a string if there are indices with , , ..., . For example, acb is a subsequence of babcaab.
Given a string , find the smallest for which some string is not a subsequence of , then count how many such strings there are. The string uses only characters of the alphabet of size .
Input
The first line has the number of test cases (). Each of the following lines has the alphabet size () and a string (), separated by a space. uses only characters from the list above.
Output
For each test case, print two integers on one line. The first integer is the smallest . The second integer is the number of such strings modulo .