#abc287e. E - Karuta

E - Karuta

Score : 500500 points

问题描述

你将获得 NN 个由小写英文字母组成的字符串。设第 ii 个(i=1,2,,Ni = 1, 2, \dots, N)字符串为 SiS_i

对于两个字符串 xxyy,定义 LCP(x,y)\mathrm{LCP}(x, y) 为满足以下所有条件的最大整数 nn

  • 字符串 xxyy 的长度均至少为 nn
  • 对于所有在 11nn 之间(含)的整数 ii,第 ii 个字符的 xx 值和 yy 值相等。

求出对所有 i=1,2,,Ni = 1, 2, \dots, N 的以下值:

  • $\displaystyle \max_{i \neq j} \mathrm{LCP}(S_i, S_j)$

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

Problem Statement

You are given NN strings consisting of lowercase English letters. Let SiS_i be the ii-th (i=1,2,,N)(i = 1, 2, \dots, N) of them.

For two strings xx and yy, LCP(x,y)\mathrm{LCP}(x, y) is defined to be the maximum integer nn that satisfies all of the following conditions:

  • The lengths of xx and yy are both at least nn.
  • For all integers ii between 11 and nn, inclusive, the ii-th character of xx and that of yy are equal.

Find the following value for all i=1,2,,Ni = 1, 2, \dots, N:

  • $\displaystyle \max_{i \neq j} \mathrm{LCP}(S_i, S_j)$

Constraints

  • 2N5×1052 \leq N \leq 5 \times 10^5
  • NN is an integer.
  • SiS_i is a string of length at least 11 consisting of lowercase English letters (i=1,2,,N)(i = 1, 2, \dots, N).
  • The sum of lengths of SiS_i is at most 5×1055 \times 10^5.

Input

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

NN

S1S_1

S2S_2

\vdots

SNS_N

Output

Print NN lines. The ii-th (i=1,2,,N)(i = 1, 2, \dots, N) line should contain $\displaystyle \max_{i \neq j} \mathrm{LCP}(S_i, S_j)$.

Sample Input 1

3
abc
abb
aac

Sample Output 1

2
2
1

$\mathrm{LCP}(S_1, S_2) = 2, \mathrm{LCP}(S_1, S_3) = 1$, and LCP(S2,S3)=1\mathrm{LCP}(S_2, S_3) = 1.

Sample Input 2

11
abracadabra
bracadabra
racadabra
acadabra
cadabra
adabra
dabra
abra
bra
ra
a

Sample Output 2

4
3
2
1
0
1
0
4
3
2
1

update @ 2024/3/10 12:00:18