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;
int main(){
int n, q;
cin >> n >> q;
vector<int> vec;
vec.push_back(1);
char ans[n + 1];
for (int i = 2; i <= n; i ++){
if (vec.size() == 0){
vec.push_back(i);
continue;
}
int l = vec.back();
cout << "? " << l << " " << i << endl;
bool regular;
cin >> regular;
if (regular){
ans[l] = '(';
ans[i] = ')';
vec.pop_back();
continue;
}
vec.push_back(i);
}
int x = vec.size();
x /= 2;
for (int i = 0; i < x; i ++){
int last = vec.back();
ans[last] = '(';
vec.pop_back();
}
for (int i = 0; i < x; i ++){
int last = vec.back();
ans[last] = ')';
vec.pop_back();
}
cout << "! ";
for (int i = 1; i <= n; i ++)
cout << ans[i];
cout << 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... |