#P14775. [ICPC 2024 Seoul R] String Rank
[ICPC 2024 Seoul R] String Rank
题目描述
Let and be strings consisting of the English lowercase alphabet. We say that a string is a subsequence of a string if there exists a strictly increasing sequence of integers , where , and for all . Here, denotes the -th character of the string . Let denote the suffix . If , then is the empty string denoted by .
Given a nonempty string and a positive integer , we define the -set of to be the set of subsequences of whose lengths are . This implies that, for any string , the empty string belongs to by definition.
For example, when , we have $Q_3(\text{aaba}) = \{\lambda, \text{a}, \text{b}, \text{ba}, \text{ab}, \text{aa}, \text{aba}, \text{aab}, \text{aaa}\}$.
For a string , we define the rank of to be the minimum integer such that the -sets for all suffixes of are all different. In other words, the rank of is $\min\{t \geq 1 \mid Q_t(w[i:]) \neq Q_t(w[j:]), \forall 1 \leq i < j \leq n\}$.
For instance, when , the 2-sets and are equal. On the other hand, for , we have
$$\begin{aligned} Q_3(\lambda) &= \{\lambda\}, \\ Q_3(\text{a}) &= \{\lambda, \text{a}\}, \\ Q_3(\text{ba}) &= \{\lambda, \text{a}, \text{b}, \text{ba}\}, \\ Q_3(\text{aba}) &= \{\lambda, \text{a}, \text{b}, \text{ba}, \text{ab}, \text{aa}, \text{aba}\}, \\ Q_3(\text{aaba}) &= \{\lambda, \text{a}, \text{b}, \text{ba}, \text{ab}, \text{aa}, \text{aba}, \text{aab}, \text{aaa}\}. \end{aligned}$$Therefore, the rank of the string is 3.
Given a string , write a program to output its rank.
输入格式
Your program is to read from standard input. The input consists of a single nonempty string , which consists only of lowercase characters from the English alphabet. The length of the string is at most .
输出格式
Your program is to write to standard output. Print exactly one line. The line should contain a positive integer to represent the rank of the input string .
aabbb
3
abacb
2
azadzzadaz
4
a
1