-
Notifications
You must be signed in to change notification settings - Fork 0
/
Arrival.cpp
66 lines (66 loc) · 1.31 KB
/
Arrival.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <bits/stdc++.h>
using namespace std;
long long ans=0;
struct Trie{
Trie *child[5];
bool end;
long long w;
Trie(){
for(int i=0;i<5;i++){
child[i]=NULL;
}
end=false;
w=0;
}
};
void insert(Trie *root,string s){
Trie *cur=root;
int c;
for(int i=0;i<s.length();i++){
if(s[i]=='A')c=0;
if(s[i]=='E')c=1;
if(s[i]=='I')c=2;
if(s[i]=='O')c=3;
if(s[i]=='U')c=4;
Trie *node = cur->child[c];
if(!node){
node = new Trie();
cur->child[c]=node;
}
cur=node;
cur->w=cur->w+1;
}
cur->end=true;
}
void traverse(Trie *root,long long level){
Trie *cur=root;
if(!cur->end){
for(int i=0;i<5;i++){
if(cur->child[i]){
ans=max(ans,level*cur->child[i]->w);
traverse(cur->child[i],level+1);
}
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin>>t;
while(t--){
ans=0;
int n;
cin>>n;
string s;
Trie *root = new Trie();
for(int i=0;i<n;i++){
cin>>s;
insert(root,s);
}
traverse(root,1);
cout<<ans<<"\n";
}
return 0;
}