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 <iostream>
#include <vector>
using namespace std;
int* S;
int* D;
int* Q;
int n;
//switch_state, switch_door, query
void b_search(int door, int pos, int a, int b)
{
if(a == b)
{
D[a] = door;
S[a] = pos;
}
else
{
int m = (a+b)/2;
for(int i = 0; i < n; i++)
{
if(S[i] != -1) Q[i] = S[i];
else
{
if(a <= i && i <= m) Q[i] = pos;
else Q[i] = !pos;
}
}
int q = tryCombination(Q);
if(q == door) b_search(door, pos, m+1, b);
else b_search(door, pos, a, m);
}
}
// ------------------------------------------------------------------------
void exploreCave(int N)
{
n = N;
int s[N], d[N], q[N];
S = s;
D = d;
Q = q;
for(int i = 0; i < N; i++) S[i] = D[i] = -1;
for(int door = 0; door < N; door++)
{
for(int i = 0; i < N; i++)
{
if(S[i] == -1) Q[i] = 0;
else Q[i] = S[i];
}
int q = tryCombination(Q);
b_search(door, q == door, 0, N-1);
}
answer(s, d);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |