# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
145741 | MathStudent2002 | 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;
const int MAXM = 5005;
int M;
int pos[MAXM];
int loc[MAXM];
int cur;
int exp[MAXM];
void found(int known, int L, int R) {
for(int i = 0; i < M; i++) {exp[i] = 1-known;}
for(int i = L; i <= R; i++) {exp[i] = known;}
for(int i = 0; i < cur; i++) {exp[loc[i]] = pos[i];}
}
void exploreCave(int N) {
M = N;
int check[M];
for(int i = 0; i < M; i++) {pos[i] = -1; loc[i] = -1;}
int curpos;
int res;
for(cur = 0; cur < M; cur++) {
found(0, 0, M-1);
for(int j = 0; j < M; j++) {
check[j] = exp[j];
}
res = tryCombination(check);
curpos = 0;
if(res == cur) {curpos = 1;}
pos[cur] = curpos;
int lo = 0, hi = M-1;
int mi;
while(hi != lo) {
mi = (lo+hi)/2;
found(curpos,lo,mi);
for(int j = 0; j < M; j++) {check[j] = exp[j];}
res = tryCombination(check);
if(res == cur) {lo = mi+1;}
else hi = mi;
}
loc[cur] = lo;
}
int ansloc[M];
int anspos[M];
for(int i = 0; i < M; i++) {
ansloc[i] = loc[i];
anspos[loc[i]] = pos[i];
}
answer(anspos, ansloc);
}