CF1551C.Interesting Story
普及/提高-
通过率:0%
时间限制:4.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Stephen Queen wants to write a story. He is a very unusual writer, he uses only letters 'a', 'b', 'c', 'd' and 'e'!
To compose a story, Stephen wrote out n words consisting of the first 5 lowercase letters of the Latin alphabet. He wants to select the maximum number of words to make an interesting story.
Let a story be a sequence of words that are not necessarily different. A story is called interesting if there exists a letter which occurs among all words of the story more times than all other letters together.
For example, the story consisting of three words "bac", "aaada", "e" is interesting (the letter 'a' occurs 5 times, all other letters occur 4 times in total). But the story consisting of two words "aba", "abcde" is not (no such letter that it occurs more than all other letters in total).
You are given a sequence of n words consisting of letters 'a', 'b', 'c', 'd' and 'e'. Your task is to choose the maximum number of them to make an interesting story. If there's no way to make a non-empty story, output 0.
斯蒂芬·奎因想要写一个故事。他是一位非常特别的作家,只使用字母 'a'、'b'、'c'、'd' 和 'e'!
为了创作一个故事,斯蒂芬写出了 n 个单词,每个单词均由拉丁字母表前五个小写字母组成。他希望从中选出尽可能多的单词,组成一个“有趣的故事”。
所谓“故事”,是指一个单词序列(单词可以重复)。若存在某个字母,它在该故事所有单词中出现的总次数严格大于其余所有字母出现次数之和,则称这个故事是“有趣的”。
例如,由三个单词 "bac"、"aaada" 和 "e" 组成的故事是有趣的(字母 'a' 共出现 5 次,其余所有字母总共只出现 4 次);但由两个单词 "aba" 和 "abcde" 组成的故事则不是有趣的(不存在某个字母,其总出现次数严格超过其余所有字母的总出现次数)。
现给出由 n 个仅含字母 'a'、'b'、'c'、'd' 和 'e' 的单词组成的序列。你的任务是选出其中尽可能多的单词,使其构成一个有趣的故事。如果无法构成非空的故事,请输出 0。
输入格式
The first line contains one integer t (1≤t≤5000) — the number of test cases. Then t test cases follow.
The first line of each test case contains one integer n (1≤n≤2⋅105) — the number of the words in the sequence. Then n lines follow, each of them contains a word — a non-empty string consisting of lowercase letters of the Latin alphabet. The words in the sequence may be non-distinct (i. e. duplicates are allowed). Only the letters 'a', 'b', 'c', 'd' and 'e' may occur in the words.
It is guaranteed that the sum of n over all test cases doesn't exceed 2⋅105; the sum of the lengths of all words over all test cases doesn't exceed 4⋅105.
第一行包含一个整数 t(1≤t≤5000)—— 测试用例的数量。随后是 t 个测试用例。
每个测试用例的第一行包含一个整数 n(1≤n≤2⋅105)—— 序列中单词的数量。接下来是 n 行,每行包含一个单词 —— 一个由拉丁字母小写字母组成的非空字符串。序列中的单词可能不互异(即允许重复)。单词中仅可能出现字母 'a'、'b'、'c'、'd' 和 'e'。
保证所有测试用例的 n 之和不超过 2⋅105;所有测试用例中所有单词的长度之和不超过 4⋅105。
输出格式
For each test case, output the maximum number of words that compose an interesting story. Print 0 if there's no way to make a non-empty interesting story.
对于每个测试用例,输出能构成一个有趣故事的最多单词数。如果无法构造出非空的有趣故事,则输出 0。
输入输出样例
输入#1
6 3 bac aaada e 3 aba abcde aba 2 baba baba 4 ab ab c bc 5 cbdca d a d e 3 b c ca
输出#1
3 2 0 2 3 2
说明/提示
In the first test case of the example, all 3 words can be used to make an interesting story. The interesting story is "bac aaada e".
In the second test case of the example, the 1-st and the 3-rd words can be used to make an interesting story. The interesting story is "aba aba". Stephen can't use all three words at the same time.
In the third test case of the example, Stephen can't make a non-empty interesting story. So the answer is 0.
In the fourth test case of the example, Stephen can use the 3-rd and the 4-th words to make an interesting story. The interesting story is "c bc".
在示例的第一个测试用例中,全部 3 个单词均可用于构成一个有趣的故事情节。该有趣的故事情节为 “bac aaada e”。
在示例的第二个测试用例中,第 1 个和第 3 个单词可用于构成一个有趣的故事情节。该有趣的故事情节为 “aba aba”。Stephen 无法同时使用全部三个单词。
在示例的第三个测试用例中,Stephen 无法构造出非空的有趣故事情节。因此答案为 0。
在示例的第四个测试用例中,Stephen 可以使用第 3 个和第 4 个单词来构成一个有趣的故事情节。该有趣的故事情节为 “c bc”。
输入解题思路,AI测评打分。不知道怎么写?