#include <bits/stdc++.h>
using namespace std;
#define int long long
#include "cave.h"
void exploreCave(int N) {
int n = N;
int a[n] = {}, b[n] = {};
vector<int> used(n, 0); // which switches are already fixed
for (int i = 0; i < n; i++){
b[i] = -1;
}
for (int i = 0; i < n; ++i) {
// set all unused switches to 0
for (int j = 0; j < n; ++j) if (!used[j]) a[j] = 0;
int x = tryCombination(a);
int berk = (x > i || x == -1) ? 0 : 1;
// build list of unused switches
vector<int> unused;
for (int j = 0; j < n; ++j) if (!used[j]) unused.push_back(j);
// binary search over unused switches
int L = 0, R = (int)unused.size() - 1;
int pos = unused.size() - 1;
while (L <= R) {
int mid = (L + R) / 2;
for (int k = 0; k <= mid; ++k) a[unused[k]] = berk;
for (int k = mid + 1; k < (int)unused.size(); ++k) a[unused[k]] = 1 ^ berk;
x = tryCombination(a);
if (x > i || x == -1) {
pos = mid;
R = mid - 1;
} else {
L = mid + 1;
}
}
int ans = unused[pos];
b[ans] = i;
used[ans] = 1;
a[ans] = berk; // fix this switch permanently
}
answer(a, b);
}
// main(){
// exploreCave(5);
// }
| # | 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... |