# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
988727 | Ariadna | Cave (IOI13_cave) | C++14 | 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 "cave.h"
#include <bits/stdc++.h>
using namespace std;
void exploreCave(int N) {
vector<int> pos(N, -1), door(N, -1);
vector<int> s(N);
for (int d = 0; d < N; ++d) {
int correct_pos = 0;
for (int i = 0; i < N; ++i)
if (pos[i] != -1) s[i] = pos[i];
else s[i] = 0;
if (tryCombination(s) == d) correct_pos = 1;
int l = 0, r = N-1, ans;
vector<int> s(N);
while (l <= r) {
int m = (l+r)/2;
for (int i = 0; i < N; ++i) {
if (pos[i] != -1) s[i] = pos[i];
else if (i < m) s[i] = correct_pos;
else s[i] = 1-correct_pos;
}
int res = tryCombination(s);
if (res > d || res == -1) {
r = m-1;
} else {
ans = m;
l = m+1;
}
}
pos[ans] = correct_pos;
door[ans] = d;
}
answer(pos, door);
}