#include <bits/stdc++.h>
#include "cave.h"
using namespace std;
void exploreCave(int N) {
int S[N], D[N];
bool used[N] = {false};
for (int door = 0; door < N; door++) {
int comb[N] = {0};
// Try each unused switch to find which one controls this door
for (int i = 0; i < N; i++) {
if (used[i]) {
comb[i] = S[i]; // already known state
} else {
comb[i] = 0; // test with switch i off
}
}
int failingDoor = tryCombination(comb);
int switchIndex = -1;
for (int i = 0; i < N; i++) {
if (used[i]) continue;
comb[i] = 1;
failingDoor = tryCombination(comb);
if (failingDoor == door) {
switchIndex = i;
S[i] = 1;
break;
}
comb[i] = 0;
failingDoor = tryCombination(comb);
if (failingDoor == door) {
switchIndex = i;
S[i] = 0;
break;
}
}
D[switchIndex] = door;
used[switchIndex] = 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... |