Codeforces Round #329 (Div. 2) A.2char violence

Source: Internet
Author: User

A. 2Char

Andrew often reads articles in his favorite magazine 2Char. The main feature of these articles is, and each of the them uses at most of the 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 doing so, he removes some words from the chosen article, in such a-the-the-the-remaining text can be written using no mor E than, 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.


The first line of the input contains number n (1≤ n ≤100)-the number of words in the article Chosen by Andrew. Following is nlines, each of them contains one word. All the words consist only of small 中文版 letters and their total length doesn ' t exceed 1000. The words is not guaranteed to being distinct, in this case you is allowed to use a word in the article as many times as it appears in the input.


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

Sample Test (s) input

In the first sample the optimal-choose words is {'abb ', 'aaa ', 'BBB '}.

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

Test Instructions : give you n a string containing only lowercase letters, now pick out any string, the largest number, but the selected string contains only two kinds of letters

How to preprocess the letter types of each string

In the violent enumeration of the two strings just fine

///1085422276#include <bits/stdc++.h>using namespacestd; typedefLong Longll;#defineMem (a) memset (A,0,sizeof (a))inline ll read () {ll x=0, f=1; CharCh=GetChar ();  while(ch<'0'|| Ch>'9')    {        if(ch=='-') f=-1; CH=GetChar (); }     while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; CH=GetChar (); }    returnx*F;}//****************************************#defineMAXN 1000000+5#defineMoD 1000000007Vector<int>g[ -];inth[ $];intaa[ -],n;Chara[101][1001];intMain () {mem (H); scanf ("%d",&N);  for(intI=1; i<=n;i++) {scanf ("%s", A[i]); intflag=0;  for(intj=0; J<strlen (A[i]); J + +) {H[a[i][j]]++; Flag++;        G[i].push_back (A[i][j]); } Aa[i]=Flag; }    intsum; intans=0;  for(intI='a'; i<='Z'; i++){         for(intj='a'; j<='Z'; j + +){            if(I==J)Continue; Sum=0;  for(intk=1; k<=n;k++){                        BOOLcan=1;  for(intg=0; G<g[k].size (); g++){                        if(G[K][G]!=I&AMP;&AMP;G[K][G]!=J) can=0; }                if(CAN) sum+=strlen (A[k]); } ans=Max (Sum,ans); }}cout<<ans<<Endl; return 0;}

Codeforces Round #329 (Div. 2) A.2char violence

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.