# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
492471 | 1ne | 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) {
/* ... */
int cur = 0;
int swit[n] = {-1};
int ans[n] = {0};
while(cur<n){
int left = 0,right = n-1;
while(left<=right){
int val = -1;
for (int j = 0;j<2;++j){
vector<int>temp(n,0);
int mid = (left + right)>>1;
for (int i = 0;i<mid;++i){
if (swit[i]==-1){
temp[i] = j;
}
else temp[i] = ans[i];
}
for (int i = mid;i<n;++i){
if (swit[i]==-1){
temp[i] = j;
}
else{
temp[i] = ans[i];
}
}
int a = tryCombination(temp);
if (a>cur){
val = j;
break;
}
}
assert(val!=-1);
vector<int>temp(n,0);
int mid = (left + right)>>1;
for (int i = 0;i<mid;++i){
if (swit[i]==-1){
temp[i] = val;
}
else temp[i] = ans[i];
}
for (int i = mid;i<n;++i){
if (swit[i]==-1){
temp[i] = val^1;
}
else temp[i] = ans[i];
}
int a = tryCombination(temp);
if (a>cur){
right = mid-1;
}
else{
left = mid;
}
}
swit[left] = cur;
ans[left] = val;
++cur;
}
answer(ans,swit);
}