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;
int N;
int doDoor(int door, int s[], int d[], bool fixed[]) {
int upperLimit = N-1;
int lowerLimit = 0;
int b;
for (int i = 0; i < N; i++)
{
if (!fixed[i])
{
s[i] = 1;
}
}
int t = tryCombination(s);
if (t == door) //door is closed on a 1
{
b = 1;
}
else
{
b = 0;
}
for (int i = 0; i < N; i++)
{
if (!fixed[i])
{
s[i] = 1-b;
}
}
while (upperLimit > lowerLimit)
{
int midpoint = (upperLimit + lowerLimit)/2;
for (int i = lowerLimit; i <= midpoint; i++)
{
if (!fixed[i])
{
s[i] = b;
}
}
int x = tryCombination(s);
if (x == door) //case where door closed
{
upperLimit = midpoint;
}
else //case where door opened
{
lowerLimit = midpoint+1;
}
for (int i = lowerLimit; i <= midpoint; i++)
{
if (!fixed[i])
{
s[i] = 1-b;
}
}
}
return lowerLimit;
}
void exploreCave(int n) {
int s[n];
int d[n];
bool fixed[n];
N = n;
for (int i = 0; i < n; i++)
{
s[i] = 0;
d[i] = 0;
fixed[i] = false;
}
for (int i = 0; i < n; i++)
{
int ans = doDoor(i, s, d, fixed);
d[ans] = i;
fixed[ans] = true;
}
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... |