# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1099715 | Ninedesu | 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;
void exploreCave(int N) {
vector<int>test(N),lock(N),pos(N),D(N);
for(int i=0; i<N; i++){
lock[i] = -1;
}
for(int i=0; i<N; i++){
int thisans;
for(int j=0; j<N; j++){
if(lock[j]!=-1)test[j] = lock[j];
else test[j] = 0;
}
int door = tryCombination(test);
thisans = (door == i);
int l=0,r=N-1;
while(l<r){
int mid=(l+r)/2;
for(int j=i; j<=mid; j++){
if(lock[j]!=-1)test[j] = lock[j];
else test[j] = 0;
}
for(int j=mid+1; j<=r; j++){
if(lock[j]!=-1)test[j] = lock[j];
else test[j] = 1;
}
door = tryCombination(test);
if(door > i){
if(!thisans){
r=mid;
}
else{
l=mid+1;
}
}
else{
if(!thisans){
l=mid+1;
}
else{
r=mid;
}
}
}
pos[i]=l;
lock[l]=thisans;
}
for(int i=0; i<N; i++){
D[pos[i]]=i;
}
answer(lock,D);
}