传统题 1000ms 256MiB

E - Karuta

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

E - Karuta

Score : $500$ points

Problem Statement

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

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

  • The lengths of $x$ and $y$ are both at least $n$.
  • For all integers $i$ between $1$ and $n$, inclusive, the $i$-th character of $x$ and that of $y$ are equal.

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

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

Constraints

  • $2 \leq N \leq 5 \times 10^5$
  • $N$ is an integer.
  • $S_i$ is a string of length at least $1$ consisting of lowercase English letters $(i = 1, 2, \dots, N)$.
  • The sum of lengths of $S_i$ is at most $5 \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 $N$ lines. The $i$-th $(i = 1, 2, \dots, N)$ line should contain $\displaystyle \max_{i \neq j} \mathrm{LCP}(S_i, S_j)$.


3
abc
abb
aac
2
2
1

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


11
abracadabra
bracadabra
racadabra
acadabra
cadabra
adabra
dabra
abra
bra
ra
a
4
3
2
1
0
1
0
4
3
2
1

2024暑假入门组刷题营第三期(一)

未参加
状态
已结束
规则
IOI
题目
8
开始于
2024-7-8 13:00
结束于
2024-7-8 15:00
持续时间
2 小时
主持人
参赛人数
7