Advertisement
a53

Subsecvente

a53
Dec 23rd, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. #include<cstdio>
  2. #include<cstring>
  3. #include <algorithm>
  4. #define NODES 2600100
  5. using namespace std;
  6. int p2,lg,mask,i,j,k,p,q,n,sol(int),s[2][NODES];
  7. char cod[NODES];
  8. char a[50010];
  9. int main()
  10. {
  11. freopen("subsecvente.in","r",stdin);
  12. freopen("subsecvente.out","w",stdout);
  13. int n; scanf("%d\n", &n);
  14. for(p2=1,n=1;scanf("%s",a+1)+1;p2<<=1)
  15. {
  16. lg=strlen(a+1);mask|=p2;
  17. for(i=1;i<=lg;i++)
  18. {
  19. j=min(i+59,lg);
  20.  
  21. for(k=i,p=1;k<=j;k++){q=a[k]-'a';if(!s[q][p])s[q][p]=++n;p=s[q][p];cod[p]|=p2;}
  22. }
  23. }
  24. cod[1]=mask;
  25. printf("%d\n",sol(1)-1);
  26. return 0;
  27. }
  28. int sol(int nod)
  29. {
  30. int sa,sb;
  31. if(!nod||cod[nod]!=mask)return 0;
  32. sa=sol(s[0][nod]);
  33. sb=sol(s[1][nod]);
  34. return max(sa,sb)+1;
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement