#include <bits/stdc++.h>
using namespace std;
vector<char> ans;
bool query(int l, int r) {
bool v;
cout << "? " << ++l << " " << ++r << endl;
cin >> v;
return v;
}
void solve(int l, int r) {
if (l >= r) return;
ans[l] = '(';
ans[r] = ')';
bool L, R;
if (l + 1 == r) return;
L = query(l, l + 1);
R = query(r - 1, r);
ans[l + 1] = L;
ans[r - 1] = !R;
if (L && R) {
ans[l + 1] = ')';
ans[r - 1] = '(';
solve(l + 2, r - 2);
} else if (L) {
ans[l + 1] = ')';
ans[r - 1] = ')';
ans[l + 2] = '(';
solve(l + 3, r - 1);
} else if (R) {
ans[l + 1] = '(';
ans[r - 1] = '(';
ans[r - 2] = ')';
solve(l + 1, r - 3);
} else {
ans[l + 1] = '(';
ans[r - 1] = ')';
solve(l + 2, r - 2);
}
}
int main() {
int N, Q;
cin >> N >> Q;
ans = vector<char>(N, '-');
solve(0, N - 1);
cout << "! ";
for (int i = 0; i < N; i++) cout << ans[i];
}
# | 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... |