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 endl '\n'
#define F first
#define S second
#define pb push_back
#define all(a) a.begin(),a.end()
const int N=4e3;
const int off=1<<20;
const int MOD=1e9+7;
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n,q;
cin >> n >> q;
int mns=1;
string s;
int cnt=n/2;
for(int i=0;i<n;i++)s+='?';
for(int i=2;i<=n;i++){
if(i-mns<=0)mns=1;
cout.flush()<<"? "<<i-mns<<' '<<i<<endl;
int ans;
cin >> ans;
if(ans){
s[i-mns-1]='(';
s[i-1]=')';
mns+=2;
// i++;
cnt--;
}
else mns=1;
}
int l=cnt,r=cnt;
for(int i=0;i<n;i++){
if(s[i]=='?'){
if(l){
s[i]=')';
l--;
}
else{
s[i]='(';
r--;
}
}
}
cout.flush()<<"! "<<s<<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... |