String Rank
Time limit0.5sMemory limit2048 MB
Given a string w of length up to 3 times 10^6, find the smallest t such that all suffixes of w have pairwise different sets of subsequences of length at most t.
- Level
Hard8 of 10
- Topics
- String, Greedy, Implementation
- Solved
- No attempts yet
Problem
Let and be strings of lowercase English letters. A string is a subsequence of if there is a strictly increasing sequence of integers with , , and for all . Here, is the -th character of the string . Let denote the suffix . If , then is the empty string, denoted .
Given a nonempty string and a positive integer , the -set of is the set of subsequences of whose lengths are . By this definition, the empty string is always in .
For example, when is aaba, .
The rank of is the minimum integer such that the -sets of all suffixes of are pairwise different. Formally, the rank is .
For instance, when is aaba, the 2-sets and are equal. For , the suffix sets are , , , , and . All five are different, so the rank of aaba is 3.
Input
The input consists of a single nonempty string made only of lowercase English letters. The length of is at most .
Output
Print exactly one line containing a positive integer, the rank of .