QOJ.ac

QOJ

Limite de temps : 1.0 s Limite de mémoire : 512 MB Points totaux : 100 Hackable ✓

#14540. 给小狗起名字

Statistiques

源源在七夕节买了一只可爱的小狗。但在告诉他的爱人之前,他需要给小狗起个名字。

令 $\overline{s}$ 表示字符串 $s$ 的翻转。给定一个长度为 $n$ 的字符串 $s$,如果一个长度为 $n'$ ($n' < n$) 的字符串 $s'$ 既是 $s$ 的前缀,且 $\overline{s'}$ 也是 $s$ 的后缀,则称 $s'$ 是 $s$ 的一个 anti-border。

他的爱人非常喜欢 anti-border,因此源源决定为小狗选择一个拥有最长 anti-border 的名字。然而,源源只能选择一个他会拼写的名字。

正式地讲,源源会拼写的单词集合为 $\{s_1, s_2, s_3, \dots, s_n\}$。所有可能的名字组成的集合 $S$ 定义如下:

  • $s_i \in S$ ($1 \le i \le n$)。
  • 若 $x, y \in S$,则 $x + y \in S$。这里的 $+$ 表示简单的字符串拼接。

令 $f(s)$ 表示 $s$ 的最长 anti-border 的长度。请帮助源源计算 $\max_{x \in S} \{f(x)\}$,或者告诉他结果是无穷大(infinity)。

输入格式

第一行包含一个整数 $n$,表示字符串的数量。

第 $i + 1$ 行($1 \le i \le n$)包含一个字符串 $s_i$。

保证 $1 \le n \le 5000$,$1 \le \sum_{i=1}^n |s_i| \le 5000$,且单词仅由小写字母组成。

输出格式

如果结果为无穷大,输出 INF;否则输出一个整数表示结果。

样例

输入样例 1

4
ab
cbba
bccd
eddc

输出样例 1

6

输入样例 2

3
abcdefg
gfe
dcba

输出样例 2

INF

说明

在第一个样例中,当 $x = s_1 + s_3 + s_4 + s_2$ 时,$f(x) = 6$。可以证明不存在 $x \in S$ 使得 $f(x) > 6$。因此结果为 6。

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.