# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
284636 | triplem5ds | 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;
int W[5005];
int ans[5005];
int S[5005];
void exploreCave(int N) {
n = N;
memset(ans, -1, sizeof ans);
for(int i = 0; i < N; i++){
for(int j = 0; j < N; j++)if(ans[j] == -1)S[j] = 0;
else S[j] = ans[j];
int x = tryCombination(S);
if(x == -1)x = N;
bool f = (x <= i); ///the door is closed then it should be open by the other state
///find which switch is it
int lo = 0, hi = N - 1 - i;
while(lo < hi){
int md = lo + (hi - lo) / 2;
int cnt = 0;
for(int j = 0; j < N; j++){
if(ans[j] != -1)S[j] = ans[j];
else {
S[j] = (f ^ (cnt > md));
cnt++;
}
}
int x = tryCombination(S);
if(x == -1)x = N;
if(x > i)
hi = md;
else
lo = md + 1;
}
int cnt = 0;
for(int j = 0; j < n; j++){
if(ans[j] == -1){
if(cnt == lo){
ans[j]=f;
W[j] = i;
break;
}
cnt++;
}
}
}
answer(ans,W);
}