CF965E.Short Code
提高+/省选-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Arkady's code contains n variables. Each variable has a unique name consisting of lowercase English letters only. One day Arkady decided to shorten his code.
He wants to replace each variable name with its non-empty prefix so that these new names are still unique (however, a new name of some variable can coincide with some old name of another or same variable). Among such possibilities he wants to find the way with the smallest possible total length of the new names.
A string a is a prefix of a string b if you can delete some (possibly none) characters from the end of b and obtain a.
Please find this minimum possible total length of new names.
阿卡迪的代码中包含 n 个变量。每个变量具有一个仅由小写英文字母组成的唯一名称。某天,阿卡迪决定缩短他的代码。
他希望将每个变量名替换为其某个非空前缀,使得所有新名称仍然互不相同(但某个变量的新名称可以与另一个变量或其自身原来的某个旧名称相同)。在所有满足上述条件的方案中,他希望找到一种使新名称总长度最小的方案。
若字符串 a 可通过从字符串 b 末尾删除若干(可能为零)字符得到,则称 a 是 b 的一个前缀。
请找出这种新名称总长度的最小可能值。
输入格式
The first line contains a single integer n (1≤n≤105) — the number of variables.
The next n lines contain variable names, one per line. Each name is non-empty and contains only lowercase English letters. The total length of these strings is not greater than 105. The variable names are distinct.
第一行包含一个整数 n(1≤n≤105)—— 变量的个数。
接下来的 n 行每行包含一个变量名。每个变量名非空,且仅由小写英文字母组成。这些字符串的总长度不超过 105。所有变量名互不相同。
输出格式
Print a single integer — the minimum possible total length of new variable names.
输出一个整数——新变量名的最小可能总长度。
输入输出样例
输入#1
3 codeforces codehorses code
输出#1
6
输入#2
5 abba abb ab aa aacada
输出#2
11
输入#3
3 telegram digital resistance
输出#3
3
说明/提示
In the first example one of the best options is to shorten the names in the given order as "cod", "co", "c".
In the second example we can shorten the last name to "aac" and the first name to "a" without changing the other names.
在第一个例子中,一种最优方案是按给定顺序将名称缩写为“cod”、“co”、“c”。
在第二个例子中,我们可以将最后一个名字缩写为“aac”,将第一个名字缩写为“a”,而无需更改其他名字。
输入解题思路,AI测评打分。不知道怎么写?