# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
410800 | AlexRex0 | 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:
bool visitado[5002];
int posiciones[5002];
int S[5002];
int prueba(int ini, int n){
for(int i = 0; i < n; ++i){
if(!visitado[i]){
S[i] = 0;
}
}
if(tryCombination(S) >= ini){
return 1;
}
return 2;
}
void bs(int tipo, int busco, int fin){
int medio, ini = 0, res = -1;
fin--;
for(int i = 0; i <= fin; ++i){
if(!visitado[i]){
if(tipo == 2){
S[i] = 1;
}else{
S[i] = 0;
}
}
}
while(ini <= fin){
medio = (ini + fin) / 2;
for(int i = medio + 1; i <= fin; ++i){
if(!visitado[i]){
if(tipo == 1){
S[i] = 1;
}else{
S[i] = 0;
}
}
}
if(tryCombination(S) >= busco){
res = medio;
fin = medio - 1;
}else{
for(int i = ini; i <= medio; ++i){
if(!visitado[i]){
if(tipo == 1){
S[i] = 0;
}else{
S[i] = 1;
}
}
}
ini = medio + 1;
}
}
visitado[res] = true;
if(tipo == 1){
S[res] = 0;
}else{
S[res] = 1;
}
posiciones[res] = busco;
}
void exploreCave(int N) {
for(int i = 0; i < N; ++i){
int aux = prueba(i, N);
bs(aux, i, N);
}
answer(S, posiciones);
}