fork(1) download
  1. #include <bits/stdc++.h>
  2. #define debug(x) cout << #x " = " << (x) << endl
  3. #define endl '\n'
  4.  
  5. using namespace std;
  6.  
  7. const int MS = 'z' - 'a' + 1;
  8. const int MN = 1000 * 1000 + 1000;
  9.  
  10. struct trie {
  11. struct node {
  12. int c;
  13. int to[MS];
  14. };
  15.  
  16. node tree[MN];
  17. int nodes;
  18.  
  19. void clear(int node = 0) {
  20. if (node == 0) nodes = 1;
  21. memset(tree[node].to, -1, sizeof tree[node].to);
  22. tree[node].c = 0;
  23. }
  24.  
  25. int insert(const string &s) {
  26. int state = 0;
  27. for (int i = 0; i < s.size(); ++i) {
  28. int c = s[i] - 'a';
  29. if (tree[state].to[c] == -1) {
  30. clear(nodes);
  31. tree[state].to[c] = nodes;
  32. nodes++;
  33. }
  34. state = tree[state].to[c];
  35. if (tree[state].c) return false;
  36. }
  37. tree[state].c++;
  38. for (int i = 0; i < MS; ++i)
  39. if (tree[state].to[i] != -1) return false;
  40. return true;
  41. }
  42. };
  43.  
  44. trie tree;
  45. int main() {
  46. ios_base::sync_with_stdio(false);cin.tie(NULL);
  47. int n;
  48. while (cin >> n && n) {
  49. tree.clear();
  50. int ok = true;
  51. for (int i = 0; i < n; ++i) {
  52. string line; cin >> line;
  53. if (ok)
  54. ok &= tree.insert(line);
  55. }
  56. if (!ok)
  57. cout << "Conjunto Ruim" << endl;
  58. else
  59. cout << "Conjunto Bom" << endl;
  60. }
  61. return 0;
  62. }
Success #stdin #stdout 0s 109056KB
stdin
3
bjsjgsdfsjf
xdfvhjfsdkjfs
vhzsdkdb
3
asdfghiiiiii
asdfg
vdbjdvsbjdjb
0
stdout
Conjunto Bom
Conjunto Ruim