fork download
  1. #include<bits/stdc++.h>
  2. #define DIST(x1,x2, y1, y2) (((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)))
  3. #define DIST3D(x1,x2, y1, y2, z1, z2) (((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)) + ((z1-z2)*(z1-z2)))
  4. #define CLR(a) a.clear()
  5. #define VCLR(a, n) for(int i=0; i<=n+3; i++) a[i].clear()
  6. #define SIZE(a) a.size()
  7. #define ERASE(a, b) memset(a, b, sizeof a)
  8. #define PB(a, b) a.push_back(b)
  9. #define PB2(a,i,b) a[i].push_back(b)
  10. #define LL long long
  11. #define ULL unsigned long long
  12. #define DBG cout<<"I Am Here"<<endl
  13. #define DBGA(a) cout<<a<<endl
  14. #define DBGI(b,a) cout<<b<<' '<<a<<endl
  15. #define DBGL(i,s,e,b) or(int i=s; i<=e; i++) cout<<b<<endl
  16. #define INF 1e9
  17. #define INV 1e-6
  18. #define sc(a) scanf("%I64d", &a)
  19. #define SC(a) scanf("%lld", &a)
  20. #define pr(a) printf("%I64d\n", a)
  21. #define PR(a) printf("%lld\n", a)
  22. #define si(a) scanf("%d", &a)
  23. #define pii pair<int,int>
  24. #define PII pair<LL,LL>
  25. #define MAX 600005
  26. #define CASE(i) printf("Case %d: ", i);
  27. #define PI acos(-1)
  28. #define piis pair<int, string>
  29. #define fast1 ios_base::sync_with_stdio(false);
  30. #define fast2 cin.tie(0)
  31.  
  32. using namespace std;
  33.  
  34. LL MOD = 1000000007;
  35.  
  36. LL bigmod(LL a, LL b){
  37. LL x = 1, y = a%MOD;
  38. while(b > 0) {
  39. if(b%2 == 1) {
  40. x=(x*y);
  41. if(x>MOD) x%=MOD;
  42. }
  43. y = (y*y);
  44. if(y>MOD) y%=MOD;
  45. b /= 2;
  46. }
  47. return x;
  48. }
  49.  
  50. LL MODINVERSE(LL a){
  51. return bigmod(a, MOD-2);
  52. }
  53.  
  54. //LL dp[900][1000];
  55. //LL NCR(int n, int r)
  56. //{
  57. // if(r==1) return n;
  58. // else if(n==r) return 1;
  59. // else
  60. // {
  61. // if(dp[n][r]!=-1) return dp[n][r];
  62. // else
  63. // {
  64. // dp[n][r]=NCR(n-1,r) + NCR(n-1,r-1);
  65. // return dp[n][r];
  66. // }
  67. // }
  68. //}
  69.  
  70. bool flag;
  71.  
  72. struct node{
  73. bool endmark;
  74. node *next[27];
  75. node()
  76. {
  77. endmark = false;
  78. for(int i=0; i<26; i++) next[i] = NULL;
  79. }
  80. }*root;
  81.  
  82. void INSERT(string str, int len)
  83. {
  84. node *curr = root;
  85. for(int i=0; i<len; i++)
  86. {
  87. int idx = str[i] - 'a';
  88. if(curr->next[idx]==NULL)
  89. curr->next[idx] = new node();
  90. curr = curr->next[idx];
  91. }
  92. curr->endmark = true;
  93. }
  94.  
  95. bool SEARCH(string str, int len)
  96. {
  97. flag = false;
  98. node *curr = root;
  99. for(int i=0; i<len; i++)
  100. {
  101. int idx = str[i] - 'a';
  102. if(curr->next[idx]==NULL) return false;
  103. curr = curr->next[idx];
  104. if(curr->endmark==true && i+1!=len) flag = true;
  105. }
  106. return curr->endmark;
  107. }
  108.  
  109. void DELETE(node *curr)
  110. {
  111. for(int i=0; i<26; i++)
  112. if(curr->next[i]) DELETE(curr->next[i]);
  113. delete (curr);
  114. }
  115.  
  116. string arr[100005];
  117.  
  118. int main()
  119. {
  120. int n;
  121. while(scanf("%d", &n)&& n>0){
  122. root = new node();
  123. map<string, int>mymap;
  124. mymap.clear();
  125. bool check = false;
  126.  
  127. for(int i=0; i<n; i++)
  128. {
  129. string str;
  130. cin>>str;
  131. arr[i] = str;
  132. if(mymap[str]>0) check = true;
  133. mymap[str]++;
  134. INSERT(str, str.size());
  135. }
  136. if(check){
  137. printf("Conjunto Ruim\n");
  138. continue;
  139. }
  140. bool found = false;
  141. for(int i=0; i<n; i++)
  142. {
  143. string str;
  144. str = arr[i];
  145. SEARCH(str, str.size());
  146. if(flag)
  147. found = true;
  148. }
  149. if(!found)
  150. puts("Conjunto Bom");
  151. else
  152. puts("Conjunto Ruim");
  153. DELETE(root);
  154. }
  155. return 0;
  156. }
  157.  
  158.  
Success #stdin #stdout 0s 3856KB
stdin
3
sjdhdh
dhdhd
ertrttyy
3
asdfg
sdfg
fgh
3
aefgh
aefg
sedrgh
0
stdout
Conjunto Bom
Conjunto Bom
Conjunto Ruim