999ms

https://codeforces.com/gym/102168/problem/F

Jan 27th, 2020
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.53 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define all(x) (x).begin(),(x).end()
  3.  
  4. using namespace std;
  5. using ll = long long;
  6.  
  7. char ask(const vector<int>& a, const vector<int>& b) {
  8.     cout << "? " << a.size() << "\n";
  9.     for (int val : a) {
  10.         cout << val + 1 << ' ';
  11.     }
  12.     cout << '\n';
  13.     for (int val : b) {
  14.         cout << val + 1 << ' ';
  15.     }
  16.     cout << endl;
  17.     char res;
  18.     cin >> res;
  19.     return res;
  20. }
  21.  
  22. void PrintAnswer(int val) {
  23.     cout << "! " << val + 1 << endl;
  24.     exit(0);
  25. }
  26.  
  27. void Solve(vector<int> arr, char bad) {
  28.     if (arr.size() == 1) {
  29.         PrintAnswer(arr[0]);
  30.     } else if (arr.size() == 2) {
  31.         vector<int> a = {arr[0]}, b = {arr[1]};
  32.         if (ask(a, b) == bad) {
  33.             PrintAnswer(arr[1]);
  34.         } else {
  35.             PrintAnswer(arr[0]);
  36.         }
  37.     } else {
  38.         vector<int> a, b;
  39.         const int n = arr.size();
  40.         int sz = n / 3 + ((n % 3 == 2) ? 1 : 0);
  41.         for (int i = 0; i < sz; i++) {
  42.             a.push_back(arr[i]);
  43.             b.push_back(arr[i + sz]);
  44.         }
  45.         auto res = ask(a, b);
  46.         if (res == '=') {
  47.             vector<int> c;
  48.             for (int i = 2 * sz; i < n; i++) {
  49.                 c.push_back(arr[i]);
  50.             }
  51.             Solve(c, bad);
  52.         } else {
  53.             if (res == bad) {
  54.                 Solve(b, bad);
  55.             } else {
  56.                 Solve(a, bad);
  57.             }
  58.         }
  59.     }
  60. }
  61.  
  62. int main() {
  63.     ios_base::sync_with_stdio(false);
  64.     cin.tie(nullptr);
  65.     cout.tie(nullptr);
  66.     int n;
  67.     cin >> n;
  68.     vector<int> a, b;
  69.     int sz = n / 3 + (n % 3 == 2 ? 1 : 0);
  70.     for (int i = 0; i < sz; i++) {
  71.         a.push_back(i);
  72.         b.push_back(sz + i);
  73.     }
  74.     auto res = ask(a, b);
  75.     if (res == '=') {
  76.         vector<int> c;
  77.         for (int i = 2 * sz; i < n; i++) {
  78.             c.push_back(i);
  79.         }
  80.         a.clear();
  81.         for (int i = 0; i < c.size(); i++) {
  82.             a.push_back(i);
  83.         }
  84.         Solve(c, ask(a, c));
  85.     } else {
  86.         if (n <= 9) {
  87.             for (int i = 0; i < n - 1; i++) {
  88.                 if (ask({i}, {n - 1}) != '=') {
  89.                     PrintAnswer(i);
  90.                 }
  91.             }
  92.         }
  93.         vector<int> c;
  94.         for (int i = 0; i < sz; i++) {
  95.             c.push_back(n - 1 - i);
  96.         }
  97.         sort(all(c));
  98.         auto curResult = ask(a, c);
  99.         if (curResult == '=') {
  100.             Solve(b, res);
  101.         } else {
  102.             Solve(a, res == '>' ? '<' : '>');
  103.         }
  104.     }
  105. }
Add Comment
Please, Sign In to add comment