#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
int N, Q, x;
cin >> N >> Q;
stack<int> stk;
stk.push(-1);
stk.push(0);
vector<int> close(N, -1); //-1 unknown, 0 open, 1 close
for (int i = 1; i < N; i++) {
if (stk.top() == -1) {
stk.push(i);
continue;
}
cout << "? " << stk.top() + 1 << ' ' << i + 1 << endl;
cin >> x;
if (x) {
close[stk.top()] = 0;
close[i] = 1;
stk.pop();
}
else
stk.push(i);
}
int unknown = 0;
for (auto i : close)
if (i == -1)
unknown++;
int count = 0;
for (int i = 0; i < N && count < unknown / 2; i++) {
if (close[i] == -1) {
close[i] = 1;
count++;
}
}
cout << "! ";
for (auto i : close)
cout << (i > 0 ? ')' : '(');
cout << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |