String Rank

시간 제한0.5초메모리 제한2048 MB

요약
문자열의 모든 접미사가 길이 t 이하의 서로 다른 부분수열 집합을 갖게 하는 최소 t를 구한다.
난이도

어려움10점 중 8점

유형
문자열, 동적 계획법, 그리디, 문자열 매칭
정답자
아직 제출이 없습니다

문제

Let ww and uu be strings consisting of the English lowercase alphabet. We say that a string uu is a subsequence of a string ww if there exists a strictly increasing sequence of integers i_1,⋯ ,i_ki\_1, \cdots , i\_k, where ∣w∣=n|w| = n, ∣u∣=k|u| = k and u\[j]=w\[i_j]u\[j] = w\[i\_j] for all j=1,…,kj = 1, \dots , k. Here, v\[i]v\[i] denotes the ii-th character of the string vv. Let w\[i:]w\[i:] denote the suffix w\[i]⋯w\[n]w\[i] \cdots w\[n]. If i>ni > n, then w\[i:]w\[i: ] is the empty string denoted by λ\lambda.

Given a nonempty string ww and a positive integer kk, we define the kk-set of ww to be the set Q_k(w)Q\_k(w) of subsequences of ww whose lengths are 0,1,⋯ ,k0, 1, \cdots , k. This implies that, for any string ww, the empty string λ\lambda belongs to Q_k(w)Q\_k(w) by definition.

For example, when w=w = aaba, we have Q_3(Q\_3(aaba) = \\{\lambda, a, b, ba, ab, aa, aba, aab, aaa\\}.

For a string ww, we define the rank of ww to be the minimum integer tt such that the tt-sets for all suffixes of ww are all different. In other words, the rank of ww is min⁡t≥1∣Q_t(w\[i:])≠Q_t(w\[j:]),∀1≤i<j≤𝑛\min\\{t ≥ 1 | Q\_t(w\[i:]) \ne Q\_t(w\[j:]), ∀1 ≤ i < j ≤ 𝑛\\}.

For instance, when w=w = aaba, the 22-sets Q_2(Q\_2(aba)) and Q_2(Q\_2(aaba)) are equal. On the other hand, for t=3t = 3, we have

  • Q_3(λ)=λQ\_3(\lambda) = \\{\lambda\\},
  • Q_3(Q\_3(a) = \\{\lambda, a\\},
  • Q_3(Q\_3(ba) = \\{\lambda, a, b, ba\\},
  • Q_3(Q\_3(aba) = \\{\lambda, a, b, ba, ab, aa, aba\\},
  • Q_3(Q\_3(aaba) = \\{\lambda, a, b, ba, ab, aa, aba, aab, aaa\\}.

Therefore, the rank of the string w=w = aaba is 33.

Given a string ww, write a program to output its rank.

입력

Your program is to read from standard input. The input consists of a single nonempty string ww, which consists only of lowercase characters from the English alphabet. The length of the string is at most 3×1063 \times 10^6.

출력

Your program is to write to standard output. Print exactly one line. The line should contain a positive integer to represent the rank tt of the input string ww.

예제4

  1. 예제 1

    입력
    aabbb
    
    예상 출력
    3
    
  2. 예제 2

    입력
    abacb
    
    예상 출력
    2
    
  3. 예제 3

    입력
    azadzzadaz
    
    예상 출력
    4
    
  4. 예제 4

    입력
    a
    
    예상 출력
    1