# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
672626 | paulo_ar | 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;
int s [5004];
int res [5004];
bool activos [5004];
int ans [5004];
int busqueda (bool esuno, int inde, int n, int cont){
int izq= 1, der=cont;
int mitad;
int rep=0;
int master;
int contar = 0;
while(izq<=der){
mitad=(izq+der)/2;
if(esuno)master=0;
else master=1;
int k=0;
while(indice<mitad)){
if(activos[k])
{
s[k]=res[k];
}
else{
s[k]=master;
inde++;
}
k++;
}
if(esuno)master=1;
else master=0;
while(indice<cont && k<=n-1)){
if(activos[k])
{
s[k]=res[k];
}
else{
s[k]=master;
inde++;
}
k++;
}
int p = tryCombination(s);
if(p>=inde or p==-1){
der=mitad-1;
rep=mitad;
}
else {
izq=mitad+1;
}
}
return rep;
}
void exploreCave(int N) {
int ll;
for(int i=0; i<N; i++){
res[i]=false;
}
for(int j=1; j<=N; j++){
int master=1;
for(int i=0; i<N; i++){
if(activos[i]){
s[i]=res[i];
}
else{
s[i]=master;
}
}
ll=tryCombination(s);
int des;
int a;
int cont = N-j+1;
if(ll>=j or ll==-1){
des= busqueda(true,j,N,cont);
a=1;
}
else {
des=busqueda(false,j,N,cont);
a=0;
}
activos [des]=true;
res[des]=a;
ans[des]=j-1;
}
answer(res, ans);
// int tryCombination(int S[]);
//void answer(int S[], int D[]);
//void exploreCave(int N);
}