QOJ.ac

QOJ

Limite de temps : 10 s - 20 s Limite de mémoire : 1024 MB Points totaux : 23

#5939. 中继器

Statistiques

Fegla 和 Omar 每天都喜欢玩游戏。但现在他们对所有的游戏都感到厌倦了,想要玩一个新的游戏。于是他们决定发明一个名为“复读机”(The Repeater)的游戏。

这是一个双人游戏。Fegla 写下 $N$ 个字符串。Omar 的任务是尽可能通过最少的操作次数(可能为 0 次)使所有字符串变得完全相同。操作分为以下两种:

  • 选择字符串中的任意字符并重复它(在该字符后紧接着添加一个相同的字符)。例如,Omar 可以通过一次操作将 "abc" 变为 "abbc"(通过重复字符 'b')。
  • 选择字符串中任意两个相邻且相同的字符,并删除其中一个。例如,Omar 可以通过一次操作将 "abbc" 变为 "abc"(删除其中一个 'b'),但不能将其变为 "bbc"。

这两种操作是独立的;并不要求第一种类型的操作必须紧跟第二种类型的操作(反之亦然)。

请编写一个程序,帮助 Omar 赢得游戏:判断是否可以将给定的字符串变得完全相同,如果可以,求出所需的最少操作次数。

输入格式

输入的第一行包含测试用例的数量 $T$。接下来是 $T$ 个测试用例。每个测试用例的第一行包含一个整数 $N$,表示字符串的数量。随后有 $N$ 行,每行包含一个非空字符串(每个字符串仅由小写英文字母 'a' 到 'z' 组成)。

输出格式

对于每个测试用例,输出一行 "Case #x: y",其中 $x$ 是测试用例编号(从 1 开始),$y$ 是使字符串变得完全相同的最少操作次数。如果无法使所有字符串变得完全相同,则输出 "Fegla Won"(引号仅为清晰起见)。

数据范围

$1 \le T \le 100$。 $1 \le$ 每个字符串的长度 $\le 100$。

小数据(10 分)

$N = 2$。

大数据(13 分)

$2 \le N \le 100$。

样例

输入 1

5
2
mmaw
maw
2
gcj
cj
3
aaabbb
ab
aabb
2
abc
abc
3
aabc
abbc
abcc

输出 1

Case #1: 1
Case #2: Fegla Won
Case #3: 4
Case #4: 0
Case #5: 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.