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;
int ask(int a, int b){
cout << "? " << a << " " << b << endl;
int ret; cin >> ret;
return ret;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, q; cin >> n >> q;
vector<char>ans(n + 1, '#');
stack<int>st;
int cnt = 0;
for(int i = 1; i <= n; i++){
if(st.empty()){
st.push(i);
continue;
}
int x = st.top();
if(ask(x, i)){
cnt += 2;
ans[x] = '(';
ans[i] = ')';
st.pop();
} else{
st.push(i);
}
}
int unused = n - cnt;
int tmp = unused;
cout << "! ";
for(int i = 1; i <= n; i++){
if(ans[i] == '#'){
if(tmp > unused/2) ans[i] = ')';
else ans[i] = '(';
tmp--;
}
cout << ans[i];
}
cout << endl;
return 0;
}
# | 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... |