This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define sz(x) int(x.size())
template<class T> using V = vector<T>;
using vi = V<int>;
int main() {
cin.tie(0)->sync_with_stdio(0);
int N, Q; cin >> N >> Q;
auto qry = [&](int l, int r) {
cout << "? " << l + 1 << " " << r + 1 << endl;
int res; cin >> res;
return res;
};
vi stk = {0};
string ans(N, '?');
for(int i = 1; i < N; i++) {
if (qry(stk.back(), i)) {
ans[stk.back()] = '(';
ans[i] = ')';
stk.pop_back();
} else stk.push_back(i);
}
int M = sz(stk) / 2;
for(int i = 0; i < M; i++) {
ans[stk[i]] = ')';
ans[stk[i + M]] = '(';
}
cout << "! " << ans << endl;
exit(0-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... |