#include <bits/stdc++.h>
#include "cave.h"
using namespace std;
bool isDoorOpen(int S[], int i) {
// If I don't take into account the doors before it
int result = tryCombination(S);
if (result != i) {
return true;
} else {
return false;
}
}
void exploreCave(int N) {
int S[N], D[N];
bool used[N] = {false};
for (int door = 0; door < N; door++) {
for (int i = 0; i < N; i++) {
if (!used[i]) {
S[i] = 0;
}
}
int l = 0, r = N - 1, switchIndex = -1;
bool result1 = isDoorOpen(S, door);
bool result2;
while (l < r) {
for (int i = 0; i < N; i++) {
if (!used[i]) {
S[i] = 0;
}
}
int mid = l + (r - l) / 2;
for (int i = l; i <= mid; i++) {
if (!used[i]) {
S[i] ^=1;
}
}
result2 = isDoorOpen(S, door);
if (result1 != result2) {
r = mid;
} else {
l = mid + 1;
}
}
D[l] = door;
if (!result2) {
S[l] ^= 1;
}
used[l] = true;
}
answer(S, D);
}
| # | 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... |