# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1114411 | MrAndria | Zagrade (COI20_zagrade) | C++14 | 0 ms | 0 KiB |
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 ff first
#define ss second
#define pb push_back
//#define int long long
bool query(int l,int r){
cout<<"? "<<l<<" "<<r<<endl;
bool b2;
cin>>b2;
return b2;
}
int main(){
cin>>n>>q;
v.pb(i);
for(int i=1;i<=n;i++){
v.pb(i);
if(v.size()<2){
continue;
}
b1=query(v[v.size()-2],v[v.size()-1]);
if(b1){
c[v[v.size()-2]]='(';
c[v[v.size()-1]]=')';
v.pop_back();
v.pop_back();
}
}
if(v.size()){
cout<<"! ";
cout<<-1<<endl;
}else{
for(int i=1;i<=n;i++){
cout<<c[i];
}
cout<<endl;
}
}