# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1174856 | trvhung | Cave (IOI13_cave) | C++20 | 0 ms | 0 KiB |
#include "cave.h"
void exploreCave(int N) {
int sw[N], fx[N], ofSw[N];
fill(fx, fx + N, -1);
for (int d = 0; d < N; ++d) {
for (int i = 0; i < N; ++i)
sw[i] = fx[i] == -1 ? 0 : fx[i];
int cur = tryCombination(sw);
int l = 0, r = N - 1;
while (l != r) {
int mid = (l + r) >> 1;
for (int i = l; i <= mid; ++i)
sw[i] = fx[i] == -1 ? 1 : fx[i];
int ask = tryCombination(sw);
for (int i = l; i <= mid; ++i)
sw[i] = fx[i] == -1 ? 0 : fx[i];
if (ask == cur)
l = mid + 1;
else
r = mid;
}
fx[l] = (cur == d);
ofSw[l] = d;
}