# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
346645 | Pety | 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 <bits/stdc++.h>
#include "cave.h"
using namespace std;
const int N = 5000;
bool found[N + 2];
int Switch[N + 2], query[N + 2], s[N + 2], d[N + 2];
//int tryCombination (int s[]);
int ask (int n, int mij, int state) {
for (int i = 0; i < n; i++)
if (found[i])
query[i] = Switch[i];
else if (i <= mij)
query[i] = state;
else
query[i] = 1 - state;
return tryCombination(query);
}
void explore (int n) {
for (int i = 0; i < n; i++) {
bool state;
if (ask(n, n - 1, 1) > i)
state = 1;
else
state = 0;
int st = 0, dr = n - 1, poz = 0;
while (st <= dr) {
int mij = (st + dr) / 2;
int aux = ask(n, mij, state);
if (aux > i || aux == -1) {
dr = mij - 1;
poz = mij;
}
else
st = mij + 1;
}
d[poz] = i;
s[poz] = state;
found[poz] = 1;
Switch[poz] = state;
}
answer(s, d);
}