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>
#define int long long
#define pb push_back
#define pii pair<int, int>
#define fr first
#define sc second
#define query(l, r) cout << "? " << l << " " << r << endl; cin >> res;
using namespace std;
const int N = 1e5 + 5;
string ans;
bool res;
signed main() {
ios_base::sync_with_stdio(false);
cout.tie(NULL);
cin.tie(NULL);
int n, q;
cin >> n >> q;
ans.assign(n, ' ');
stack<int> s;
s.push(1);
int cnt = 0;
for (int i = 2; i <= n; i++) {
if (s.empty()) {
s.push(i);
continue;
}
int cur = s.top();
query(cur, i);
if (res) {
ans[cur - 1] = '(';
ans[i - 1] = ')';
cnt++;
s.pop();
} else
s.push(i);
}
int cntfrr = n / 2 - cnt;
for (int i = 0; i < n; i++) {
if (ans[i] == ' ') {
if (cntfrr) {
ans[i] = ')';
cntfrr--;
} else
ans[i] = '(';
}
}
cout << "! " << ans << 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... |