Universal Cup Judging System

Universal Cup

Time Limit: 1.0 s Memory Limit: 1024 MB Total points: 100 Hackable ✓
Statistics

長さ $n$ の文字列 $s$ が与えられます。

$1 \le i \le n$ を満たす各位置 $i$ について、$s$ から $s$ の $i$ 番目の文字を削除し(他のすべての文字の相対的な順序を保ったまま)得られる文字列を $t_i$ とします。

$2$ つの文字列 $x$ と $y$ に対して、$\operatorname{lcp}(x, y)$ でそれらの最長共通接頭辞の長さ、すなわち $x$ と $y$ の先頭 $\ell$ 文字が等しくなる($x_1 = y_1, x_2 = y_2, \dots, x_\ell = y_\ell$ となる)最大の整数 $\ell \ge 0$ を表すことにします。

あなたの課題は、値 $\operatorname{lcp}(t_i, t_j)$ ができるだけ大きくなるように $2$ つの異なる位置 $i$ と $j$ を選び、この達成可能な最大値を求めることです。

形式的には、次を求める必要があります:

$$\max_{1 \le i < j \le n} \operatorname{lcp}(t_i, t_j).$$

$i$ や $j$ を出力する必要はなく、$\operatorname{lcp}(t_i, t_j)$ の最大値のみを出力してください。

入力

$1$ 行目には、テストケースの数を表す単一の整数 $T$ ($1 \le T \le 2 \cdot 10^5$) が含まれます。

各テストケースは、文字列 $s$ ($2 \le |s| \le 5 \cdot 10^5$) を含む $1$ 行からなります。$s$ は英小文字のみを含み、$|s|$ の総和は $5 \cdot 10^5$ を超えないことが保証されます。

出力

各テストケースについて、すべての添字の組 $i \ne j$ にわたる $\operatorname{lcp}(t_i, t_j)$ の達成可能な最大値を表す単一の整数を、それぞれ別の行に出力してください。

入出力例

入力例 1

5
abac
abbbb
cbacb
babcc
aa

出力例 1

2
4
3
4
1

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.