#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
#define fi first
#define se second
int main(){
cin.tie(0); ios_base::sync_with_stdio(0);
int n, q;
cin >> n >> q;
char ans[n];
memset(ans, '?', sizeof(ans));
int s=0, pe=-2, ps=-8;
for(int e=1; e<n; e++){
cout << '?' << ' ' << s+1 << ' ' << e+1 << endl;
bool temp;
cin >> temp;
if(temp){
ans[s] = '(';
ans[e] = ')';
if(s - pe == 1){
s = ps-1;
}
else{
ps = s;
s = s-1;
}
pe = e;
}
else{
s = e;
}
}
int qc = 0;
int tqc = 0;
for(int i=0; i<n; i++){
if(ans[i] == '?'){
tqc++;
}
}
cout << '!' << ' ';
for(int i=0; i<n; i++){
if(ans[i] == '?'){
qc++;
if(qc > tqc/2){
ans[i] = '(';
}
else{
ans[i] = ')';
}
}
cout << ans[i];
}
cout << endl;
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... |