fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. const int maxn = 200000;
  5. struct node
  6. {
  7. int child[10];
  8. int cnt;
  9. int isword;
  10. void clear()
  11. {
  12. memset(child, 0, sizeof child );
  13. cnt = isword = 0;
  14. }
  15. }tire[maxn];
  16. int sz;
  17. int flag;
  18.  
  19. void insert(char *s)
  20. {
  21. int u, tmp, i;
  22. u = 0;
  23. if(!flag) return ;
  24. for(i=0; s[i]; ++i)
  25. {
  26. tmp = s[i] - '0';
  27. if(!tire[u].child[tmp])
  28. {
  29. tire[++sz].clear();
  30. tire[u].child[tmp] = sz;
  31. }
  32. u = tire[u].child[tmp];
  33. if(tire[u].isword == 1 )
  34. {
  35. flag = 0;
  36. return ;
  37. }
  38. tire[u].cnt++;
  39. }
  40. tire[u].isword = 1;
  41. if(tire[u].cnt > 1)
  42. flag = 0;
  43. }
  44. int main()
  45. {
  46. int T, n, i;
  47. char str[20];
  48. scanf("%d",&T);
  49. while(T--)
  50. {
  51. scanf("%d",&n);
  52. flag = 1;
  53. sz = 0;
  54. tire[sz].clear();
  55. while(n--)
  56. {
  57. scanf("%s",str);
  58. insert(str);
  59. }
  60. if(flag) puts("YES");
  61. else puts("NO");
  62. }
  63. return 0;
  64. }
  65.  
Runtime error #stdin #stdout 0s 12712KB
stdin
Standard input is empty
stdout
Standard output is empty