fork download
  1. /*
  2. Submitted With (^^) by -> Hossam ^_^
  3.  _____________________
  4. | ___ ___ |
  5. | (^_^) (^_^) |
  6. | /( | )\_/( | )\ |
  7. |_____|_|_____|_|_____|
  8. */
  9.  
  10. #include <bits/stdc++.h>
  11.  
  12. using namespace std;
  13.  
  14. inline void prep()
  15. {
  16. cin.tie(0);
  17. cin.sync_with_stdio(0);
  18. }
  19.  
  20. #define X first
  21. #define Y second
  22. #define ll long long
  23. #define inf (0x7fffffffffffffff)
  24. #define all(x) x.begin(), x.end()
  25. #define ZXC cerr << clock() * 1.0 / CLOCKS_PER_SEC << endl;
  26.  
  27. const int mod = (int)1e9 + 7;
  28. const int MX = (int)1e6 + 5;
  29.  
  30. int main()
  31. {
  32. prep();
  33.  
  34. int tc;
  35. cin >> tc;
  36. int T = tc;
  37.  
  38. while (tc--)
  39. {
  40.  
  41. int n, l;
  42. cin >> n >> l;
  43.  
  44. vector<string> s(n);
  45. bool ch[30][30][30];
  46. bool mask[30][30];
  47. memset(ch, 0, sizeof ch);
  48. memset(mask, 0, sizeof mask);
  49.  
  50. for (int i = 0; i < n; ++i)
  51. {
  52. cin >> s[i];
  53. for (int idx = 0; idx < l; ++idx)
  54. {
  55. if (idx + 1 < l)
  56. ch[s[i][idx] - 'A'][idx][(s[i][idx + 1] - 'A')] = 1;
  57. mask[idx][s[i][idx] - 'A'] = 1;
  58. }
  59. }
  60.  
  61. string res = s[rand() % n];
  62. bool found = false;
  63. for (int c = 0; c < 26; ++c)
  64. {
  65. for (int idx = 0; idx + 1 < l; ++idx)
  66. {
  67. for (int i = 0; i < 26; ++i)
  68. {
  69. if (mask[idx][c] && ch[c][idx][i] ^ mask[idx + 1][i])
  70. {
  71. found = true;
  72. res[idx] = 'A' + c;
  73. res[idx + 1] = 'A' + i;
  74. break;
  75. }
  76. }
  77. if (found)
  78. break;
  79. }
  80. if (found)
  81. break;
  82. }
  83.  
  84. cout << "Case #" << T - tc << ": " << (found ? res : "-") << "\n";
  85. }
  86.  
  87. // ZXC
  88. return 0;
  89. }
  90.  
Success #stdin #stdout 0s 4180KB
stdin
1
8 4
AAAA
ABAA
BAAA
BBAA
AABA
ABBA
AABB
AAAB
stdout
Case #1: -