# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
163128 | mhy908 | 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"
int now[5010], where[5010];
bool ch[5010];
void rev(int a, int b){
for(int i=a; i<=b; i++)if(!ch[i])now[i]^=1;
}
void binsearch(int st, int fin, bool fl, int num){
if(st==fin)return st;
int mid=(st+fin)/2;
if(fl){
rev(a, mid);
if(tryCombination(now)!=num){
rev(a, mid);
return binsearch(st, mid, fl, num);
}
rev(a, mid);
return binsearch(mid+1, fl, num);
}
else{
rev(a, mid);
if(tryCombination(now)==num){
rev(a, mid);
return binsearch(st, mid, fl, num);
}
rev(a, mid);
return binsearch(mid+1, fl, num);
}
}
void exploreCave(int n){
for(int i=0; i<n; i++){
int temp=tryCombination(now);
int but=binsearch(0, n-1, temp==i);
if(temp==i){
where[but]=i;
ch[but]=true;
}
else{
where[but]=i;
rev(but, but);
ch[but]=true;
}
}
answer(now, where);
}