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 fi first
#define se second
#define endl "\n"
#define pii pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define pque priority_queue
#define pqueg priority_queue<ll,vector<ll>,greater<ll>>
#define que queue<ll>
#define FOR(m,i,n) for(int i=(m); i<=(n); i++)
#define FORM(m,i,n) for(int i=(m); i>=(n); i--)
ll n,q,temp;
ll a,cnt;
stack<ll> st;
char ans[100100];
int main() {
cin >> n >> q;
FOR(1,i,n) {
if(!st.empty()) {
cout << "? " << st.top() << " " << i << endl;
cin >> a;
if(a == 1) {
ans[st.top()] = '(';
ans[i] = ')';
cnt += 2;
st.pop();
}
else {
st.push(i);
}
}
else {
st.push(i);
}
}
cnt = n - cnt;
temp = cnt;
FOR(1,i,n) {
if(temp > cnt/2 && ans[i] != ')' && ans[i] != '(') {
ans[i] = ')';
temp--;
}
else if(ans[i] != ')' && ans[i] != '(') {
ans[i] = '(';
}
}
cout << "! ";
FOR(1,i,n) {
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... |