#abc285b. B - Longest Uncommon Prefix

B - Longest Uncommon Prefix

Score : 200200 points

问题描述

你将得到一个长度为 NN 的由小写英文字母组成的字符串 SS。其中,第 xx 个(1xN1 \le x \le N)字符记为 SxS_x

对于每个 i=1,2,,N1i=1,2,\dots,N-1,找出满足以下所有条件的最大非负整数 ll

  • l+iNl+i \leq N,且
  • 对于所有满足 1kl1 \leq k \leq l 的整数 kk,均有 SkSk+iS_{k} \neq S_{k+i}

注意:l=0l=0 总是满足上述条件。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You are given a string SS of length NN consisting of lowercase English letters. The xx-th (1xN)(1 \le x \le N) character of SS is SxS_x.

For each i=1,2,,N1i=1,2,\dots,N-1, find the maximum non-negative integer ll that satisfies all of the following conditions:

  • l+iNl+i \le N, and
  • for all integers kk such that 1kl1 \le k \le l, it holds that SkSk+iS_{k} \neq S_{k+i}.

Note that l=0l=0 always satisfies the conditions.

Constraints

  • NN is an integer such that 2N50002 \le N \le 5000.
  • SS is a string of length NN consisting of lowercase English letters.

Input

The input is given from Standard Input in the following format:

NN

SS

Output

Print (N1)(N-1) lines. The xx-th (1x<N)(1 \le x < N) line should contain the answer as an integer when i=xi=x.

Sample Input 1

6
abcbac

Sample Output 1

5
1
2
0
1

In this input, S=S= abcbac.

  • When i=1i=1, we have S1S2,S2S3,S_1 \neq S_2, S_2 \neq S_3, \dots, and S5S6S_5 \neq S_6, so the maximum value is l=5l=5.
  • When i=2i=2, we have S1S3S_1 \neq S_3 but S2=S4S_2 = S_4, so the maximum value is l=1l=1.
  • When i=3i=3, we have S1S4S_1 \neq S_4 and S2S5S_2 \neq S_5 but S3=S6S_3 = S_6, so the maximum value is l=2l=2.
  • When i=4i=4, we have S1=S5S_1 = S_5, so the maximum value is l=0l=0.
  • When i=5i=5, we have S1S6S_1 \neq S_6, so the maximum value is l=1l=1.

update @ 2024/3/10 11:55:10