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 int long long
//#define endl '\n'
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define F first
#define S second
#define sz(x) (int)(x).size()
#define pb push_back
const int mod = 1e7 + 7;
const int N = 1e6 + 15;
const ll inf = 1e18;
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
stack<int> st;
st.push(0);
int n,q;
cin >> n >> q;
vector<char> a(n,'x');
bool valid;
int op=n/2,cl=n/2; // number of open bracket needed ..
for (int i=1;i<n;i++){
cout << "? " << st.top()+1 << ' ' << i+1 << endl;
cin >> valid;
if (valid){
a[st.top()] = '(';
a[i] = ')';
op--;cl--;
st.pop();
}
else {
st.push(i);
}
}
// now they are )))(((
for (int i=0;i<op;i++){
a[st.top()] = '(';
st.pop();
}
for (int i=0;i<cl;i++){
a[st.top()] = ')';
st.pop();
}
cout << "! "; for (auto it : a) cout << it ;
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... |