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()
bool ask(int l, int r){
cout << "? " << l << " " << r << endl;
int rt; cin >> rt;
return rt;
}
signed main(){
int n,q; cin >> n >> q;
vector<bool> small(n+5,0);
for(int i=1; i<n; i++){
small[i] = ask(i,i+1);
}
vector<int> p(n+5,0), s(n+5,0);
for(int i=1; i<=n; i++){
p[i] = p[i-1]+1-small[i-1];
}
for(int i=n; i>0; i--){
s[i] = s[i+1]+1-small[i];
}
int bp=-1;
for(int i=1; i<n; i++){
if(p[i]==s[i+1]){
bp=i;
break;
}
}
assert(bp!=-1);
cout << "! ";
for(int i=1; i<=n; i++){
if(small[i]) cout << "()", i++;
else{
if(i<=bp) cout << "(";
else cout << ")";
}
}
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... |