fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. using ll = long long;
  5.  
  6. int func = 0;
  7. int ask(string a) {
  8. func++;
  9. assert(func <= 12);
  10. for (auto& i : a) {
  11. assert('0' <= i && i <= '9');
  12. }
  13. cout << "? " << a << endl;
  14. int x;
  15. cin >> x;
  16. return x;
  17. }
  18.  
  19. int32_t main() {
  20. ios::sync_with_stdio(false);
  21. cin.tie(nullptr), cout.tie(nullptr);
  22.  
  23. char dummy = '?';
  24. vector<int> xat(10, -1);
  25.  
  26. for (int i = 0; i < 10; i++) {
  27. char c = char('0' + i);
  28. string cur = string(3, c);
  29. xat[i] = ask(cur);
  30.  
  31. if (xat[i] == 3) {
  32. cout << "! " << cur << endl;
  33. return 0;
  34. }
  35. if (xat[i] == 0) {
  36. dummy = c;
  37. break;
  38. }
  39. }
  40.  
  41. int cur_match = 0;
  42. string ans = string(3, dummy);
  43.  
  44. auto solve_1 = [&](int i) -> void {
  45. char c = char('0' + i);
  46. vector<int> av;
  47. for (int j = 0; j < 3; j++) {
  48. if (ans[j] == dummy) av.push_back(j);
  49. }
  50.  
  51. int ok = 0;
  52. for (int j = 0; j + 1 < av.size(); j++) {
  53. ans[av[j]] = c;
  54. int x = ask(ans);
  55. if (x == cur_match + 1) {
  56. ok = 1;
  57. break;
  58. }
  59. ans[av[j]] = dummy;
  60. }
  61. if (!ok && av.size()) {
  62. ans[av.back()] = c;
  63. }
  64. if (av.size())
  65. cur_match++;
  66. };
  67.  
  68. auto solve_2 = [&](int i) -> void {
  69. char c = char('0' + i);
  70. vector<pair<int, int>> av;
  71. for (int j = 0; j < 3; j++) {
  72. for (int k = j + 1; k < 3; k++)
  73. if (ans[j] == dummy && ans[k] == dummy) av.push_back({j, k});
  74. }
  75.  
  76. int ok = 0;
  77. for (int j = 0; j + 1 < av.size(); j++) {
  78. ans[av[j].first] = c;
  79. ans[av[j].second] = c;
  80. int x = ask(ans);
  81. if (x == cur_match + 2) {
  82. ok = 1;
  83. break;
  84. }
  85. ans[av[j].first] = dummy;
  86. ans[av[j].second] = dummy;
  87. }
  88. if (!ok && av.size()) {
  89. ans[av.back().first] = c;
  90. ans[av.back().second] = c;
  91. }
  92. if (av.size())
  93. cur_match += 2;
  94. };
  95.  
  96. for (int i = 0; i < 9; i++) {
  97. if (xat[i] == 0) {
  98. continue;
  99. }
  100.  
  101. if (xat[i] != -1) {
  102. if (xat[i] == 1) {
  103. solve_1(i);
  104. }
  105. else if (xat[i] == 2) {
  106. solve_2(i);
  107. }
  108. if (cur_match == 3) {
  109. cout << "! " << ans << endl;
  110. return 0;
  111. }
  112. continue;
  113. }
  114.  
  115. xat[i] = ask(string(3, '0' + i));
  116. if (xat[i] == 3) {
  117. cout << "! " << string(3, '0' + i) << endl;
  118. return 0;
  119. }
  120.  
  121. if (xat[i] == 1) {
  122. solve_1(i);
  123. }
  124. if (xat[i] == 2) {
  125. solve_2(i);
  126. }
  127.  
  128. if (cur_match == 3) {
  129. cout << "! " << ans << endl;
  130. return 0;
  131. }
  132. }
  133.  
  134. for (auto& i : ans) if (i == dummy) i = '9';
  135. cout << "! " << ans << endl;
  136.  
  137. return 0;
  138. }
Success #stdin #stdout 0.01s 5324KB
stdin
Standard input is empty
stdout
? 000
? 111
? 222
? 333
? 444
? 555
? 666
? 777
? 888
! 999