fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. int ask(const vector<pair<int, int>>& cells) {
  7. if (cells.empty()) return 0;
  8. cout << "? " << cells.size();
  9. for (auto p : cells) {
  10.  
  11. cout << " " << p.first + 1 << " " << p.second + 1;
  12. }
  13. cout << "\n";
  14. cout.flush();
  15.  
  16. int ans;
  17. cin >> ans;
  18. return ans;
  19. }
  20.  
  21. void solve() {
  22.  
  23. vector<int> active_diags = {0, 1, 2, 3, 4, 5, 6, 7};
  24. int W = 33;
  25.  
  26. while (active_diags.size() > 1) {
  27. int mid = active_diags.size() / 2;
  28. vector<int> left_half(active_diags.begin(), active_diags.begin() + mid);
  29. vector<int> right_half(active_diags.begin() + mid, active_diags.end());
  30.  
  31. vector<pair<int, int>> query_cells;
  32. for (int k : left_half) {
  33. for (int r = 0; r < 8; ++r) {
  34. query_cells.push_back({r, (r + k) % 8});
  35. }
  36. }
  37.  
  38. int X = ask(query_cells);
  39. if (X > 4 * (int)left_half.size()) {
  40. active_diags = left_half;
  41. W = X;
  42. } else {
  43. active_diags = right_half;
  44. W = W - X;
  45. }
  46. }
  47.  
  48. int target_k = active_diags[0];
  49. vector<pair<int, int>> D;
  50. for (int r = 0; r < 8; ++r) {
  51. D.push_back({r, (r + target_k) % 8});
  52. }
  53.  
  54.  
  55. int V[4];
  56. V[0] = ask({D[0], D[1]});
  57. V[1] = ask({D[2], D[3]});
  58. V[2] = ask({D[4], D[5]});
  59. V[3] = W - V[0] - V[1] - V[2];
  60.  
  61. vector<pair<int, int>> ans;
  62. vector<int> one_pairs;
  63.  
  64.  
  65. for (int i = 0; i < 4; ++i) {
  66. if (V[i] == 2) {
  67. ans.push_back(D[2 * i]);
  68. ans.push_back(D[2 * i + 1]);
  69. } else if (V[i] == 1) {
  70. one_pairs.push_back(i);
  71. }
  72. }
  73.  
  74.  
  75. while (ans.size() > 5) ans.pop_back();
  76.  
  77. for (int p_idx : one_pairs) {
  78. if (ans.size() == 5) break;
  79.  
  80.  
  81. int v = ask({D[2 * p_idx]});
  82. if (v == 1) {
  83. ans.push_back(D[2 * p_idx]);
  84. } else {
  85. ans.push_back(D[2 * p_idx + 1]);
  86. }
  87. }
  88.  
  89.  
  90. cout << "!";
  91. for (int i = 0; i < 5; ++i) {
  92. cout << " " << ans[i].first + 1 << " " << ans[i].second + 1;
  93. }
  94. cout << "\n";
  95. cout.flush();
  96. }
  97.  
  98. int main() {
  99. ios_base::sync_with_stdio(false);
  100. cin.tie(NULL);
  101.  
  102. int T;
  103. if (cin >> T) {
  104. while (T--) {
  105. solve();
  106. }
  107. }
  108. return 0;
  109. }
  110.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Standard output is empty