CF593A.2Char

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Andrew often reads articles in his favorite magazine 2Char. The main feature of these articles is that each of them uses at most two distinct letters. Andrew decided to send an article to the magazine, but as he hasn't written any article, he just decided to take a random one from magazine 26Char. However, before sending it to the magazine 2Char, he needs to adapt the text to the format of the journal. To do so, he removes some words from the chosen article, in such a way that the remaining text can be written using no more than two distinct letters.

Since the payment depends from the number of non-space characters in the article, Andrew wants to keep the words with the maximum total length.

安德鲁经常阅读他最喜爱的杂志《2Char》中的文章。这些文章的主要特点是:每篇文章最多只使用两个不同的字母。安德鲁决定向《2Char》杂志投稿,但由于他尚未撰写任何文章,便决定从另一本杂志《26Char》中随机选取一篇。然而,在将该文章投递给《2Char》之前,他需要将其调整为该杂志所要求的格式。为此,他从所选文章中删除若干单词,使得剩余文本仅由至多两个不同字母构成。

由于稿酬取决于文章中非空格字符的总数,安德鲁希望保留的单词总长度尽可能大。

输入格式

The first line of the input contains number n (1 ≤ n ≤ 100) — the number of words in the article chosen by Andrew. Following are n lines, each of them contains one word. All the words consist only of small English letters and their total length doesn't exceed 1000. The words are not guaranteed to be distinct, in this case you are allowed to use a word in the article as many times as it appears in the input.

输入的第一行包含一个整数 nn(1≤n≤1001 \leq n \leq 100)——表示安德鲁所选文章中的单词数量。接下来有 nn 行,每行包含一个单词。所有单词均由小写英文字母组成,且所有单词的总长度不超过 10001000。单词不一定互不相同;若存在重复单词,则允许在文章中使用该单词的次数等于其在输入中出现的次数。

输出格式

Print a single integer — the maximum possible total length of words in Andrew's article.

输出一个整数——安德鲁文章中单词总长度的最大可能值。

输入输出样例

  • 输入#1

    4
    abb
    cacc
    aaa
    bbb

    输出#1

    9
  • 输入#2

    5
    a
    a
    bcbcb
    cdecdecdecdecdecde
    aaaa

    输出#2

    6

说明/提示

In the first sample the optimal way to choose words is {'abb', 'aaa', 'bbb'}.

In the second sample the word 'cdecdecdecdecdecde' consists of three distinct letters, and thus cannot be used in the article. The optimal answer is {'a', 'a', 'aaaa'}.

在第一个样例中,选择单词的最优方案是 {'abb', 'aaa', 'bbb'}。

在第二个样例中,单词 'cdecdecdecdecdecde' 包含三个不同的字母,因此不能用于该文章。最优答案是 {'a', 'a', 'aaaa'}。

输入解题思路,AI测评打分。不知道怎么写?

首页