Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define all(x) (x).begin(),(x).end()
- using namespace std;
- using ll = long long;
- int itr = 0;
- char ask(const vector<int>& a, const vector<int>& b) {
- itr++;
- if (itr > 9) {
- while (true);
- }
- cout << "? " << a.size() << "\n";
- for (int val : a) {
- cout << val + 1 << ' ';
- }
- cout << '\n';
- for (int val : b) {
- cout << val + 1 << ' ';
- }
- cout << endl;
- char res;
- cin >> res;
- return res;
- }
- void PrintAnswer(int val) {
- cout << "! " << val + 1 << endl;
- exit(0);
- }
- void Solve(vector<int> arr, char bad) {
- if (arr.size() == 1) {
- PrintAnswer(arr[0]);
- } else if (arr.size() == 2) {
- if (ask({arr[0]}, {arr[1]}) == bad) {
- PrintAnswer(arr[1]);
- } else {
- PrintAnswer(arr[0]);
- }
- } else {
- vector<int> a, b;
- const int n = arr.size();
- int sz = n / 3 + ((n % 3 == 2) ? 1 : 0);
- for (int i = 0; i < sz; i++) {
- a.push_back(arr[i]);
- b.push_back(arr[i + sz]);
- }
- auto res = ask(a, b);
- if (res == '=') {
- vector<int> c;
- for (int i = 2 * sz; i < n; i++) {
- c.push_back(arr[i]);
- }
- Solve(c, bad);
- } else {
- if (res == bad) {
- Solve(b, bad);
- } else {
- Solve(a, bad);
- }
- }
- }
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int n;
- cin >> n;
- vector<int> a, b, c, d;
- int sz = n / 3;
- for (int i = 0; i < sz; i++) {
- a.push_back(i);
- b.push_back(sz + i);
- c.push_back(sz * 2 + i);
- }
- for (int i = 3 * sz; i < n; i++) {
- d.push_back(i);
- }
- auto res1 = ask(a, b);
- if (res1 == '=') {
- auto res2 = ask(a, c);
- if (res2 == '=') {
- a.clear();
- for (int i = 0; i < d.size(); i++) {
- a.push_back(i);
- }
- Solve(d, ask(a, d));
- } else {
- Solve(c, res2);
- }
- } else {
- auto res2 = ask(c, a);
- if (res2 == '=') {
- Solve(b, res1);
- } else {
- Solve(a, res2);
- }
- }
- }
Add Comment
Please, Sign In to add comment