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;
#define ll long long
#define pii pair<int,int>
#define pb push_back
#define ff first
#define ss second
int main(){
ios_base::sync_with_stdio(NULL);cin.tie(NULL);
int n,q,ok;cin>>n>>q;
char ans[n+1];
stack<int>st;
for(int i=1;i<=n;i++){
if(st.size()==0){
st.push(i);
continue;
}
cout<<"? "<<st.top()<<" "<<i<<endl;
cin>>ok;
if(ok){
ans[st.top()]='(';
ans[i]=')';
st.pop();
}
else{
st.push(i);
}
}
int n1=st.size();
for(int i=0;i<n1/2;i++){
ans[st.top()]='(';
st.pop();
}
while(st.size()){
ans[st.top()]=')';
st.pop();
}
cout<<"! ";
for(int i=1;i<=n;i++)cout<<ans[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... |