Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- char s[50005][203];
- int mx;
- struct node
- {
- bool endmark;
- int counter;
- node *next[4];
- node()
- {
- counter = 0;
- endmark = false;
- for(int i=0; i<2; i++)
- {
- next[i] = NULL;
- }
- }
- }*root;
- void Insert(char *str,int len)
- {
- node *curr = root;
- int child = 0;
- 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->counter++;
- child++;
- mx = max(mx,(child*curr->counter));
- }
- curr->endmark = true;
- }
- void del(node *curr)
- {
- for(int i=0; i<2; i++)
- {
- if(curr->next[i])
- {
- del(curr->next[i]);
- }
- }
- delete(curr);
- }
- int main()
- {
- int num,i,a,test,len;
- scanf("%d",&test);
- while(test--)
- {
- root = new node();
- scanf("%d",&num);
- mx = 0;
- for(i=1; i<=num; i++)
- {
- scanf("%s",s[i]);
- len = strlen(s[i]);
- Insert(s[i],len);
- }
- printf("%d\n",mx);
- del(root);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment