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;
#ifdef Nero
#include "Deb.h"
#else
#define debug(...)
#endif
bool ask(int l, int r) {
cout << "?" << ' ' << l << ' ' << r << endl;
bool ret;
cin >> ret;
return ret;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, k;
cin >> n >> k;
vector<int> stk;
vector<char> ans(n + 1);
for (int r = 1; r <= n; ++r) {
if (stk.empty()) {
stk.push_back(r);
continue;
}
int l = stk.back();
bool valid = ask(l, r);
if (valid) {
ans[l] = '(';
ans[r] = ')';
stk.pop_back();
} else {
stk.push_back(r);
}
}
int m = (int) stk.size();
for (int i = 0; i < m / 2; ++i) {
ans[stk[i]] = ')';
}
for (int i = m / 2; i < m; ++i) {
ans[stk[i]] = '(';
}
cout << "! ";
for (int i = 1; i <= n; ++i) {
cout << ans[i];
}
cout << endl;
return 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... |