# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1152455 | simuyu | Zagrade (COI20_zagrade) | C++20 | 0 ms | 440 KiB |
#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;
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;
try {
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--;
}
} catch (exception) {
1/0;
}
// set already yay
startpt += sz;
continue;
}
startpt++;
}
}
cout << "! " << res << endl;
return 0;
}
Compilation message (stderr)
# | 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... |