This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
bool query(int l,int r){
cout<<"? "<<l+1<<" "<<r<<endl;
int res;cin>>res;
return res;
}
int main(){
int n,q;cin>>n>>q;
stack<int>st;
st.push(0);
string ans(n,' ');
for(int i=1;i<n;i++){
if(st.empty()){
st.push(i);
continue;
}
auto res=query(st.top(),i+1);
if(res){
ans[i]=')';
ans[st.top()]='(';
st.pop();
}
else st.push(i);
}
int cnt=count(ans.begin(),ans.end(),' ');
int now=0;
for(int i=0;i<n;i++){
if(ans[i]==' ')ans[i]=(now++<cnt/2?')':'(');
}
cout<<"! "<<ans<<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... |