QOJ.ac

QOJ

Límite de tiempo: 3.0 s Límite de memoria: 512 MB Puntuación total: 100 Hackeable ✓

#15163. 最长回文路径

Estadísticas

给定一个长度为 $n$ 的字符串 $s$,对于 $s$ 的每个回文子串,我们构建一个代表它的节点。对于任意两个回文子串 $a$ 和 $b$,如果 $a$ 是 $b$ 的子串($a \neq b$),我们就添加一条从 $b$ 指向 $a$ 的有向边。显然,该图是一个 DAG(有向无环图),请找出该图中的最长路径。注意,回文串是指满足对于所有 $1 \le i \le n$ 都有 $s_i = s_{n-i+1}$ 的字符串 $s$。

输入格式

输入的第一行包含一个整数 $T$,表示测试用例的数量。

接下来的 $T$($1 \le T \le 5$)行,每行包含一个字符串 $s$($1 \le |s| \le 10^6$)。

输出格式

对于每个测试用例,在单独的一行中输出一个数字,表示答案。

样例

输入样例 1

3
baaa
aaaabbbb
abcba

输出样例 1

3
4
3

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.