QOJ.ac

QOJ

Time Limit: 5 s - 10 s Memory Limit: 1024 MB Total points: 36

#5915. 乱码邮件

Statistics

Gagan 刚刚收到她朋友 Jorge 发来的一封电子邮件。邮件中包含重要信息,但不幸的是,在发送过程中损坏了:所有的空格都丢失了,并且在删除空格后,一些字母被改成了其他字母!Gagan 现在只拥有一个由小写字母组成的字符串 $S$。

你知道这封邮件最初是由下文所述字典中的单词组成的。你还知道字母是在删除空格后被修改的,并且任意两个被修改字母的索引之差不小于 5。例如,字符串 "code jam" 可能变成了 "codejam"、"dodejbm"、"zodejan" 或 "cidejab",但不能变成 "kodezam"(因为 "k" 的修改索引和 "z" 的修改索引之间的距离只有 4)。

请问最少可能修改了多少个字母?

字典

字典包含 $W$ 个单词,每个单词长度至少为 1,至多为 10 个小写字母,并在输入文件开头给出。它并非任何自然语言的字典,尽管其中包含一些英语单词。对于单个输入文件中的所有测试用例,字典都是相同的。字典按字典序递增给出,且不包含重复单词。

输入格式

第一行包含字典中的单词数量 $W$。接下来的 $W$ 行,每行包含一个由小写字母 a-z 组成的字符串,代表字典中的一个单词。 下一行包含测试用例的数量 $T$。随后是 $T$ 个测试用例。每个测试用例包含一行,为一个由小写字母 a-z 组成的字符串 $S$。

输出格式

对于每个测试用例,输出一行 "Case #x: y",其中 $x$ 是用例编号(从 1 开始),$y$ 是为了得到 $S$ 而可能修改的最少字母数量。

数据范围

内存限制:1GB。

$W = 521196$。

字典中每个单词的长度至少为 1,至多为 10 个小写字母。

字典按字典序递增排序。

字典不包含重复单词。

字典中字符的总数为 3323296。

$S$ 是合法的:即可以通过上述方法生成。

小数据集(测试集 1 - 可见;12 分)

时间限制:5 秒。

$1 \le T \le 20$。

$1 \le \text{length of } S \le 50$。

大数据集(测试集 2 - 隐藏;24 分)

时间限制:10 秒。

$1 \le T \le 4$。

$1 \le \text{length of } S \le 4000$。

样例

样例输入 1

9
aabea
bobs
code
in
jam
oo
operation
production
system
4
codejam
cxdejax
cooperationaabea
jobsinproduction

样例输出 1

Case #1: 0
Case #2: 2
Case #3: 1
Case #4: 1

说明

"code" 和 "jam" 都出现在字典中。虽然 "cooperation" 是一个英语单词,但它没有出现在字典中;而 "aabea" 出现在字典中。

注意,为了使样例在题目描述中可见,样例中的字典大小不满足数据范围限制。

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.