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;
#define nyahalo ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define otsumiko exit(0);
#define mikodanye priority_queue<pair<long long, long long>, vector<pair<long long, long long> >, greater<pair<long long, long long> > >
#define mikochi priority_queue<long long, vector<long long>, greater<long long> >
long long n, q, x, a[100069], pi, np, ng;
stack<long long> stk;
int main() {
nyahalo
long long i, j;
cin >> n >> q;
np = n/2;
ng = n/2;
for (i=1; i<=n; i++) {
a[i] = 0;
}
if(q == n-1) {
a[1] = 1;
stk.push(1);
for (i=2; i<=n; i++) {
if (stk.empty()) {
stk.push(i);
a[i] = 1;
} else {
pi = stk.top();
cout << "? " << pi << " " << i << "\n" << flush;
cin >> x;
if (x == 1) {
a[i] = -1;
stk.pop();
} else {
a[i] = 1;
stk.push(i);
}
}
}
cout << "! ";
for (i=1; i<=n; i++) {
if (a[i] == 1) {
cout << "(";
} else {
cout << ")";
}
}
cout << "\n" << flush;
}
for (i=2; i<=n; i+=2) {
for (j=1; j<=n-i+1; j++) {
cout << "? " << j << " " << j+i-1 << "\n" << flush;;
cin >> x;
if (x == 1) {
if (a[j] == 0) {
np--;
}
a[j] = 1;
if (a[j+i-1] == 0) {
ng--;
}
a[j] = -1;
}
}
}
for (i=1; i<=n; i++) {
if (a[i] == 0) {
if (ng>0) {
a[i] = -1;
ng--;
} else {
a[i] = 1;
np--;
}
}
}
cout << "! ";
for (i=1; i<=n; i++) {
if (a[i] == 1) {
cout << "(";
} else {
cout << ")";
}
}
cout << "\n";
otsumiko
}
# | 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... |