Universal Cup Judging System

Universal Cup

حد الوقت: 1.0 s حد الذاكرة: 1024 MB مجموع النقاط: 100 قابلة للهجوم ✓
الإحصائيات

Bạn được cho một xâu $s$ có độ dài $n$.

Với mỗi vị trí $i$ thỏa mãn $1 \le i \le n$, gọi $t_i$ là xâu thu được từ $s$ bằng cách xóa ký tự thứ $i$ của $s$ (và giữ nguyên thứ tự tương đối của tất cả các ký tự khác).

Với hai xâu $x$ và $y$, gọi $\operatorname{lcp}(x, y)$ là độ dài tiền tố chung dài nhất của chúng, tức là số nguyên lớn nhất $\ell \ge 0$ sao cho $\ell$ ký tự đầu tiên của $x$ và $y$ bằng nhau (nếu $x_1 = y_1, x_2 = y_2, \dots, x_\ell = y_\ell$).

Nhiệm vụ của bạn là chọn hai vị trí khác nhau $i$ và $j$ sao cho giá trị $\operatorname{lcp}(t_i, t_j)$ lớn nhất có thể, và tính giá trị lớn nhất có thể này.

Một cách hình thức, bạn cần tìm

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

Bạn không cần in ra $i$ hay $j$, chỉ cần in ra giá trị lớn nhất của $\operatorname{lcp}(t_i, t_j)$.

Dữ liệu vào

Dòng đầu tiên chứa một số nguyên duy nhất $T$ ($1 \le T \le 2 \cdot 10^5$), biểu thị số lượng bộ test.

Mỗi bộ test gồm một dòng duy nhất chứa xâu $s$ ($2 \le |s| \le 5 \cdot 10^5$). Dữ liệu đảm bảo rằng $s$ chỉ chứa các chữ cái tiếng Anh viết thường và tổng của $|s|$ không vượt quá $5 \cdot 10^5$.

Kết quả

Với mỗi bộ test, hãy in ra một số nguyên duy nhất trên một dòng riêng biệt, biểu thị giá trị lớn nhất có thể của $\operatorname{lcp}(t_i, t_j)$ trên tất cả các cặp chỉ số $i \ne j$.

Ví dụ

Dữ liệu vào 1

5
abac
abbbb
cbacb
babcc
aa

Kết quả 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.