QOJ.ac

QOJ

시간 제한: 1 s 메모리 제한: 128 MB 총점: 100

#16590. 地名

통계

地名(toponym)是指城市、村庄、河流、山脉等的名称。在摩尔多瓦共和国,人们经常可以发现非常相似的地名。例如:Orhei 和 Orheiul Vechi;Jora de Sus、Jora de Mijloc 和 Jora de Jos。

通常,每个地名都是一个由字符 A, B, C, ..., Z, a, b, c, ..., z 以及空格组成的序列。地名中不会出现连续两个或多个空格。地名不包含前导或尾随空格。由地名的前 $m$ 个字符组成的子串称为长度为 $m$ 的前缀。例如,子串 "Jora" 是地名 "Jora de Mijloc" 的一个长度为 $m = 4$ 的前缀。

一个地名集合 $T$ 的相似度 $Ls(T)$ 定义为 $T$ 中所有地名的最长公共前缀的长度。例如,对于地名集合 $T = \{\text{Jora de Sus}, \text{Jora de Mijloc}, \text{Jora de Jos}\}$,相似度 $Ls(T) = 8$。

一个地名集合 $T$ 的复杂度 $Lc(T)$ 定义为:

$$Lc(T) = Ls(T) \times k$$

其中 $k$ 是 $T$ 中地名的数量。

例如,对于地名集合 $T = \{\text{Jora de Sus}, \text{Jora de Mijloc}, \text{Jora de Jos}\}$,复杂度 $Lc(T) = 24$。

编写一个程序,对于给定的地名集合 $S$,找到一个子集 $T \subseteq S$,使得其复杂度 $Lc(T)$ 最大。

输入格式

输入的第一行包含一个整数 $n$,表示集合 $S$ 中地名的数量。

接下来的 $n$ 行,每行包含一个地名。每个地名是由字符 A, B, C, ..., Z, a, b, c, ..., z 和空格组成的字符串。

输出格式

输出仅包含一行,一个整数,表示最大复杂度 $Lc(T)$。

数据范围

  • $2 \le n \le 1\,000\,000$
  • 任意地名的长度不超过 $20\,000$ 个字符。
  • 输入文件的大小不超过 10 MB。

样例

输入样例 1

7
Jora de Sus
Orhei
Jora de Mijloc
Joreni
Jora de Jos
Japca
Orheiul Vechi

输出样例 1

24

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.