1174: [Balkan2007]Toponyms
Time Limit: 10 Sec Memory Limit: 128 MB
Submit: 117 Solved: 16
[Submit][Status]
Description
给你一个字符集合,你从其中找出一些字符串出来. 希望你找出来的这些字符串的最长公共前缀*字符串的总个数最大化.
Input
第一行给出数字N.N在[2,1000000] 下面N行描述这些字符串,长度不超过20000 总输入不超过20000字符
Output
a single line with an integer representing the maximal level of complexity Lc(T).
Sample Input
7
Jora de Sus
Orhei
Jora de Mijloc
Joreni
Jora de Jos
Japca
Orheiul Vechi
Jora de Sus
Orhei
Jora de Mijloc
Joreni
Jora de Jos
Japca
Orheiul Vechi
Sample Output
24
HINT
Source
题解:
写了个trie树果然RE不停,trie树貌似是最明显的做法吧,还有什么神犇的做法呢?
挖坑待填
代码:
#include<cstdio> #include<cstdlib> #include<cmath> #include<cstring> #include<algorithm> #include<iostream> #include<vector> #include<map> #include<set> #include<queue> #include<string> #define inf 1000000000 #define maxn 500000 #define maxm 500+100 #define eps 1e-10 #define ll long long #define pa pair<int,int> #define for0(i,n) for(int i=0;i<=(n);i++) #define for1(i,n) for(int i=1;i<=(n);i++) #define for2(i,x,y) for(int i=(x);i<=(y);i++) #define for3(i,x,y) for(int i=(x);i>=(y);i--) #define mod 1000000007 using namespace std; inline int read() { int x=,f=;char ch=getchar(); while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();} while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();} return x*f; }
int n,tot,f[maxn],t[maxn][];
ll ans; int main() { freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); n=read();
for1(i,n)
{
int now=,len=;char ch;
while((ch=getchar())!='\n')
{
len++;
int x;
if(ch==' ')x=;else if(ch<='z'&&ch>='a')x=ch-'a';else x=ch-'A'+;
if(!t[now][x])t[now][x]=++tot;
now=t[now][x];
f[now]++;
ans=max(ans,(ll)f[now]*(ll)len);
}
}
printf("%lld\n",ans); return ; }