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 ll long long
#define ull unsigned long long
#define ld long double
#define fi first
#define se second
vector<int> v;
int ans[100005];
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
int n, q, cnt = 0;
cin >> n >> q;
v.push_back(1);
for (int i = 2; i <= n; i++) {
if (v.empty()) {
v.push_back(i);
continue;
}
int id = v.back();
cout << "? " << id << " " << i << endl;
bool in;
cin >> in;
if (in) cnt++, ans[id] = 1, ans[i] = 2, v.pop_back();
else v.push_back(i);
}
cnt = n / 2 - cnt;
cout << "! ";
for (int i = 1; i <= n; i++) {
if (ans[i] == 1) cout << '(';
else if (ans[i] == 2) cout << ')';
else if (cnt > 0) {
cout << ')';
cnt--;
}
else cout << '(';
}
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... |