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 FF first
#define SS second
#define all(a) a.begin(), a.end()
#define mod (ll)(1000000007)
bool ask(int l, int r){
int val;
cout<<"? "<<l<<' '<<r<<endl;
cin>>val;
return val;
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int n, q;
cin>>n>>q;
int a=n/2,b=n/2;
vector<int>Ans(n+1), stk;
for(int i=1;i<=n;i++){
if(stk.empty()){
stk.push_back(i);
}
else{
bool val=ask(stk.back(), i);
if(val){
Ans[stk.back()]=1, Ans[i]=2;
stk.pop_back();
a--, b--;
}
else{
stk.push_back(i);
}
}
}
cout<<"! ";
for(int i=1;i<=n;i++){
char c;
if(Ans[i]){
c='('+Ans[i]-1;
}
else{
if(a)
c=')', a--;
else
c='(';
}
cout<<c;
}
}
# | 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... |