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>
#include "cave.h"
using namespace std;
void exploreCave(int n) {
auto Ask = [&](int state[]) {
int ans = tryCombination(state);
if (ans == -1) ans = n;
return ans;
};
int *state = new int[n];
int *door = new int[n];
for (int i = 0; i < n; ++i) state[i] = 0, door[i] = -1;
auto Flip = [&](int fin) {
for (int i = 0; i <= fin; ++i)
if (door[i] == -1) state[i] ^= 1;
};
for (int i = 0; i < n; ++i) {
int pos = Ask(state);
if (pos > i) {
Flip(n - 1);
}
int lo = 0, hi = n - 1, ans = -1;
while (lo <= hi) {
int mid = lo + (hi - lo) / 2;
Flip(mid);
pos = Ask(state);
Flip(mid);
if (pos > i) {
ans = mid;
hi = mid - 1;
} else {
lo = mid + 1;
}
}
door[ans] = i;
state[ans] ^= 1;
}
assert(tryCombination(state) == -1);
answer(state, door);
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |