记录编号 415668 评测结果 AAAAAAAAAA
题目名称 词链 最终得分 100
用户昵称 GravatarHzoi_QTY 是否通过 通过
代码语言 C++ 运行时间 0.000 s
提交时间 2017-06-18 16:38:45 内存使用 0.00 MiB
显示代码纯文本
  1. #include<iostream>
  2. #include<cstring>
  3. #include<cstdlib>
  4. #include<cstdio>
  5. using namespace std;
  6. int f[50001],n,t,sz;
  7. struct trie
  8. {
  9. int dfn;
  10. trie *ch[28];
  11. } node[50001],*root;
  12. inline trie* newnode()
  13. {
  14. sz++;
  15. return &node[sz];
  16. }
  17. inline void insert(char *s)
  18. {
  19. int len=strlen(s);
  20. trie *now=root;
  21. ++t;
  22. for(int i=0;i<len;i++)
  23. {
  24. if(now->ch[s[i]-'a']==NULL)
  25. now->ch[s[i]-'a']=newnode();
  26. if(now->dfn)
  27. f[t]=max(f[now->dfn],f[t]);
  28. now=now->ch[s[i]-'a'];
  29. }
  30. now->dfn=t;
  31. f[t]++;
  32. }
  33. int yjn()
  34. {
  35. freopen("link.in","r",stdin);
  36. freopen("link.out","w",stdout);
  37. scanf("%d",&n);
  38. root=newnode();
  39. while(n--)
  40. {
  41. char a[60];
  42. scanf("%s",a);
  43. insert(a);
  44. }
  45. int s=0;
  46. for(int i=1;i<=t;i++)
  47. s=max(f[i],s);
  48. cout<<s;
  49. //while(1);
  50. }
  51. int qty=yjn();
  52. int main()
  53. {
  54. ;
  55. }