#include <bits/stdc++.h>
using namespace std;
int main() {
int N, Q;
cin >> N >> Q;
char arr[N+5];
memset(arr, 'a', sizeof(arr));
int start = 1;
int end = 2;
int count = N/2;
while (end <= N) {
int ans;
cout << "? " << start << " " << end << "\n";
Q--;
cin >> ans;
if (ans == 1) {
count--;
arr[start] = '(';
arr[end] = ')';
if (start > 1 && arr[start-1] == 'a') {
start--;
end++;}
else {
start = end+1;
end = start+1;}
}
else {
start = end;
end = start+1;
}
}
int temp = 0;
int index = 1;
while (temp < count) {
if (arr[index] == 'a') {
arr[index] = ')';
temp++;
}
index++;
}
temp = 0;
while (temp < count) {
if (arr[index] == 'a') {
arr[index] = '(';
temp++;
}
index++;
}
while (Q > 0) {
Q--;
int ans;
cout << "? " << 1 << " " << 2 << "\n";
cin >> ans;
}
cout << "! ";
for (int i = 1; i <= N; i++) cout << arr[i];
return 0;}
# | 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... |