#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
ll N, Q;
string res;
int main() {
//ios_base::sync_with_stdio(false);
//cin.tie(0);
//cout.tie(0);
cin >> N >> Q;
for (ll i=0; i<N; i++) {
res += "?";
}
ll left, right;
int resp;
ll qcnt = 0;
for (ll sz=2; sz<=N; sz+=2) {
ll startpt=0;
while (startpt<=N-sz) {
cout << "? " << startpt+1 << ' ' << startpt+sz << endl; // this is in their coordinates not ours
cin >> resp;
if (resp) {
// is valid --> pattern known
// from startpt to startpt+sz (inclusive, exclusive) is a "block"
left = startpt;
right = startpt+sz;
while (right > left) {
while (res[right-1] != '?') {
right -= 2;
if (right<=left) break;
}
while (res[left] != '?') {
left += 2;
if (right<=left) break;
}
if (right <= left) break;
/*cout << "LEFT: " << left << ", RIGHT: " << right << "; ";
for (int i=left; i<right; i++) {
cout << res[i];
}
cout << endl;*/
// now the first and last are '(' and ')'
res[left] = '(';
res[right-1] = ')';
left++;
right--;
}
// set already yay
//startpt += sz;
//continue;
}
startpt++;
qcnt ++;
if (qcnt > Q) {
while (true) {
qcnt++;
}
}
}
}
cout << "! " << res << 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... |