Universal Cup Judging System

Universal Cup

시간 제한: 1.0 s 메모리 제한: 1024 MB 총점: 100 해킹 가능 ✓
통계

給定一個長度為 $n$ 的字串 $s$。

對於每個滿足 $1 \le i \le n$ 的位置 $i$,令 $t_i$ 為從 $s$ 中刪除 $s$ 的第 $i$ 個字元(並保持所有其他字元的相對順序)後所得的字串。

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