# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
436568 | erekle | Cave (IOI13_cave) | C++17 | 0 ms | 0 KiB |
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 <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include "grader.h"
using namespace std;
void exploreCave(int N) {
int query[N] {};
set<int> indices;
for (int i = 0; i < N; ++i) indices.insert(i);
int correctPos[N], door[N];
// find switch of each door in order of doors
for (int d = 0; d < N; ++d) {
// find correct position of door
vector<int> v(indices.begin(), indices.end());
int n = N-d;
for (int i : v) query[i] = 0;
int correct = (tryCombination(query) == d ? 1 : 0);
int left = 0, right = n;
while (right - left > 1) {
int mid = (left + right) / 2;
for (int i = left; i < mid; ++i) query[v[i]] = correct;
for (int i = mid; i < right; ++i) query[v[i]] = 1-correct;
if (tryCombination(query) == d) left = mid;
else right = mid;
}
door[v[left]] = d;
correctPos[v[left]] = correct;
indices.erase(v[left]);
query[v[left]] = correct;
}
answer(correctPos, door);
}