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;
typedef vector<int> vi;
#define DOWN 1
#define UP 0
#define NA 2
int n;
vi dir;
int check(int curr, int lo, int mid, int hi) {
int arr[n];
for (int i = lo; i <= mid; i++) {
if (dir[i] == NA) arr[i] = dir[curr];
else arr[i] = dir[i];
}
for (int i = mid+1; i <= hi; i++) {
if (arr[i] == NA) arr[i] = 1-dir[curr];
}
return tryCombination(arr);
}
void exploreCave(int N) {
int S[N];
int D[N];
dir = vi(N, NA); // Dir to close door
n = N;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
S[j] = dir[j];
if (S[j] == NA) S[j] = DOWN;
}
int tmp = tryCombination(S);
if (tmp == i) {
dir[i] = DOWN;
} else
dir[i] = UP;
int lo = 0, hi = N-1, mid;
while (lo < hi) {
mid = (lo+hi)/2;
bool isDownI = check(i, lo, mid, hi) == i;
if (isDownI) {
hi = mid;
} else
lo = mid + 1;
}
D[lo] = i+1;
}
for (int i = 0; i < N; i++) S[i] = dir[i];
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... |