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 <iostream>
#include <vector>
#include <stack>
#include <climits>
#include <algorithm>
using namespace std;
int n, q, emp;
stack<int> unpaired;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> q;
string ans(n + 1, ' ');
unpaired.push(0);
for (int i = 1; i < n; i++) {
if (unpaired.empty()) {
unpaired.push(i);
continue;
}
cout << "? " << unpaired.top() << " " << i << "\n";
cout.flush();
int res; cin >> res;
if (res) {
ans[unpaired.top()] = '(';
ans[i] = ')';
unpaired.pop();
} else {
unpaired.push(i);
}
}
for (int i = 0; i < n; i++) {
if (!(ans[i] == '(' || ans[i] == ')')) emp++;
}
emp /= 2;
for (int i = 0; i < n; i++) {
if (ans[i] == '(' || ans[i] == ')') {
} else {
if (emp) {
ans[i] = ')';
emp--;
} else {
ans[i] = '(';
}
}
}
cout << "! " << ans << "\n";
cout.flush();
}
# | 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... |