The 'Winning' Gene

시간 제한1초메모리 제한1024 MB

요약
모든 (K,L) 쌍마다 길이 K 부분 문자열들의 길이 L 부분 문자열 중 사전순 최소의 시작 위치 집합을 만들 때, 서로 다른 시작 위치 개수가 v인 쌍의 수를 각 v에 대해 출력한다.
난이도

어려움10점 중 8점

유형
문자열, 정렬, 완전 탐색, 구현
정답자
아직 제출이 없습니다

문제

After years of hosting games and watching Bessie get first place over and over, Farmer John has realized that this can't be accidental. Instead, he concludes that Bessie must have winning coded into her DNA so he sets out to find this "winning" gene.

He devises a process to identify possible candidates for this "winning" gene. He takes Bessie's genome, which is a string SS of length NN where 1≤N≤30001 \leq N \leq 3000. He picks some pair (K,L)(K,L) where 1≤L≤K≤N1 \leq L \leq K \leq N representing that the "winning" gene candidates will have length LL and will be found within a larger KK length substring. To identify the gene, he takes all KK length substrings from SS which we will call a kk-mer. For a given kk-mer, he takes all length LL substrings, identifies the lexicographically minimal substring as a winning gene candidate (choosing the leftmost such substring if there is a tie), and then writes down the 00-indexed position p_ip\_i where that substring starts in SS to a set PP.

Since he hasn't picked KK and LL yet, he wants to know how many candidates there will be for every pair of (K,L)(K,L).

For each vv in 1…N1\dots N, help him determine the number of (K,L)(K,L) pairs with ∣P∣=v|P|=v.

입력

NN representing the length of the string. SS representing the given string. All characters are guaranteed to be uppercase characters where s_i∈A−Zs\_i \in A-Z since bovine genetics are far more advanced than ours.

출력

For each vv in 1…N1\dots N, output the number of (K,L)(K,L) pairs with ∣P∣=v|P|=v, with each number on a separate line.

예제1

  1. 예제 1

    입력
    8
    AGTCAACG
    
    예상 출력
    11
    10
    5
    4
    2
    2
    1
    1