# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
672751 | Hacv16 | Cave (IOI13_cave) | C++17 | 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;
typedef long long ll;
const int MAX = 2e6 + 15;
const int INF = 0x3f3f3f3f;
int S[MAX], D[MAX];
bool mark[MAX];
int findPos(int l, int r, int c, int d){
if(l == r) return l;
int m = (l + r) >> 1;
for(int i = l; i <= m; i++) if(!mark[i]) S[i] = c;
for(int i = m + 1; i <= r; i++) if(!mark[i]) S[i] = !c;
int query = tryCombination(S);
if(query == d) return findPos(m + 1, r, c, d);
return findPos(l, m, c, d);
}
void exploreCave(int n){
int S[n] = { 0 }, D[n] = { 0 };
for(int door = 0; door < n; door++){
for(int i = 0; i < n; i++)
if(!mark[i]) S[i] = 0;
int color = (tryCombination(S) == door);
int pos = findPos(0, n - 1, color);
mark[l] = true;
D[l] = door;
S[l] = color;
}
answer(S, D);
}