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 int long long
#define pb push_back
#define pii pair<int,int>
#define tii tuple<int,int,int,int,int>
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
vector<char> ans;
int n;
bool ask(int l, int r){
cout << "? " << l << " " << r << endl;
int rt; cin >> rt;
return rt;
}
void solve(int l, int r){
if(r<l) return;
for(int i=l+1; i<=r; i+=2){
if(ask(l,i)){
ans[l]='(';
ans[i]=')';
solve(l+1,i-1);
solve(i+1,r);
break;
}
}
return;
}
signed main(){
int q; cin >> n >> q;
ans.resize(n+1);
solve(1,n);
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... |