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>
bool query(int l, int r) {
std::cout << '?' << ' ' << l + 1 << ' ' << r << std::endl;
int res;
std::cin >> res;
return res == 1;
}
void answer(std::string s) {
std::cout << '!' << ' ' << s << std::endl;
std::exit(0);
}
int main() {
int N, Q;
std::cin >> N >> Q;
// valid sequence
std::stack<int> stk;
std::string ans(N, '0');
int l = 0;
for (int i = 1; i < N; ++i) {
const int r = i + 1;
const auto res = query(l, r);
if (res) {
ans[l] = '(';
ans[i] = ')';
if (stk.empty()) {
l = i + 1;
++i;
} else {
l = stk.top();
stk.pop();
}
} else {
stk.push(l);
l = i;
}
}
answer(ans);
}
# | 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... |