-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11488 - Hyper Prefix Sets.cpp
61 lines (57 loc) · 1.07 KB
/
11488 - Hyper Prefix Sets.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
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mx;
struct node
{
node *next[3];
int endmark;
node()
{
for(int i = 0; i < 2; i++)
next[i] = NULL;
endmark = 0;
}
};
void Build_trie (char *str , int len , node *curr)
{
int t;
for(int i = 0; i < len; i++)
{
int id = str[i] - '0';
if(curr-> next[id] == NULL)
{
curr->next[id] = new node();
}
curr = curr->next[id];
++curr->endmark;
t = curr->endmark * (i + 1);
if(mx < t) mx = t;
}
}
void del(node *cur) {
for(int i=0; i < 2; i++)
if(cur -> next[i])
del(cur -> next[i]);
delete (cur);
}
int main()
{
int tes;
scanf(" %d", &tes);
while(tes--)
{
char s[50005];
node *root = new node();
int num;
scanf("%d", &num);
for(int i = 0; i < num; i++)
{
scanf(" %s" ,s);
Build_trie(s, strlen(s) , root);
}
printf("%lld\n",mx);
del(root);
mx = 0;
}
}