Universal Cup Judging System

Universal Cup

Límite de tiempo: 1.0 s Límite de memoria: 1024 MB Puntuación total: 100 Hackeable ✓
Estadísticas

畀定一個長度為 $n$ 嘅字串 $s$。

對於每個滿足 $1 \le i \le n$ 嘅位置 $i$,設 $t_i$ 為將 $s$ 嘅第 $i$ 個字元刪除(並保持所有其他字元嘅相對順序)之後由 $s$ 得到嘅字串。

對於兩個字串 $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$。

你嘅任務係揀兩個唔同嘅位置 $i$ 同 $j$,令到 $\operatorname{lcp}(t_i, t_j)$ 嘅值盡可能大,並計算呢個最大可能值。

形式化噉講,你需要求:

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

你唔需要輸出 $i$ 或者 $j$,只需要輸出 $\operatorname{lcp}(t_i, t_j)$ 嘅最大值。

輸入格式

第一行包含一個整數 $T$($1 \le T \le 2 \cdot 10^5$),代表測試數據嘅組數。

每組測試數據由單獨一行組成,包含字串 $s$($2 \le |s| \le 5 \cdot 10^5$)。保證 $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.