#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
int n, q;
cin >> n >> q;
// cout << endl;
vector<char> ans(n, '.'), pos;
int l = 0, r = 0;
int res;
for(int i = 1; i < n; i++){
cout << "? " << i << " " << i + 1 << endl;
cin >> res;
if(res){
ans[i - 1] = '(';
ans[i] = ')';
pos.push_back(i + 1);
l++;
r++;
}
}
for(int i: pos){
int a = 1;
int l = i - a - 1;
int r = i + 1;
cout << i << endl;
while(0 < l && r <= n){
cout << "? " << l << " " << r << endl;
cin >> res;
if(!res) break;
ans[l - 1] = '(';
ans[r - 1] = ')';
l--;
r++;
}
}
int ptr = 0;
while(ptr < n){
if(ans[ptr] == '.') ans[ptr] = '(';
else break;
ptr++;
}
ptr = n - 1;
while(0 <= ptr){
if(ans[ptr] == '.') ans[ptr] = ')';
else break;
ptr--;
}
// int ptr = 0;
// while(l < n / 2){
// if(ans[ptr] == '.'){
// ans[ptr] = '(';
// l++;
// }
// ptr++;
// }
// if(ans[ptr] == '.'){
// ans[ptr - 1] = ')';
// ans[ptr] = '(';
// }
// while(ptr < n){
// if(ans[ptr] == '.') ans[ptr] = ')';
// ptr++;
// }
cout << "! ";
for(char i: ans) cout << i;
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... |