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;
void exploreCave(int N) {
/* ... */
vector<int> bitdoor(N, -1), sw(N, -1), door(N, -1);
auto bs = [&](int doorNo, int state) {
int lo = 0, hi = N-1, mid;
int tmp[N];
for (int i = 0; i < N; i++) if (door[i] >= 0 && bitdoor[door[i]] != -1) {
tmp[i] = bitdoor[door[i]];
} else {
tmp[i] = state;
}
while (lo < hi) {
mid = (lo + hi) >> 1;
for (int i = lo; i <= mid; i++) if (door[i] >= 0 && bitdoor[door[i]] != -1) {
tmp[i] = bitdoor[door[i]];
} else {
tmp[i] = !state;
}
int xx = tryCombination(tmp);
for (int i = lo; i <= mid; i++) if (door[i] >= 0 && bitdoor[door[i]] != -1) {
tmp[i] = bitdoor[door[i]];
} else {
tmp[i] = state;
}
if (xx == doorNo) {
hi = mid;
} else {
lo = mid+1;
}
}
return hi;
};
while (true) {
int ones[N], zeros[N];
bool done = true;
for (int i = 0; i < N; i++) {
if (door[i] >= 0 && bitdoor[door[i]] == 0) {
ones[i] = 0;
zeros[i] = 0;
} else if (door[i] >= 0 && bitdoor[door[i]] == 1) {
zeros[i] = 1;
ones[i] = 1;
} else zeros[i] = 0, ones[i] = 1, done = false;
}
// for (int i : bitdoor) cout<<i<<" ";
// cout<<endl;
// for (int i : door) cout<<i<<" ";
// cout<<endl;
if (!done) {
int x = tryCombination(ones);
int y = tryCombination(zeros);
//cout<<x<<" "<<y<<endl;
if (x == -1) x = N;
if (y == -1) y = N;
if (x < y) {
for (int i = x; i < y; i++) if (bitdoor[i] == -1) {
bitdoor[i] = 0;
}
if (bitdoor[y] == -1) bitdoor[y] = 1;
} else if (y < x) {
for (int i = y; i < x; i++) if (bitdoor[i] == -1) {
bitdoor[i] = 1;
}
if (bitdoor[x] == -1) bitdoor[x] = 0;
}
}
for (int i = 0; i < N; i++) if (sw[i] == -1 && bitdoor[i] != -1) {
sw[i] = bs(i, bitdoor[i]);
door[sw[i]] = i;
}
for (int i = 0; i < N; i++) if (sw[i] == -1) {
done = false;
}
if (done) {
int ans2[N]; for (int i = 0; i < N; i++) ans2[i] = door[i];
int ans1[N]; for (int i = 0; i < N; i++) ans1[i] = bitdoor[door[i]];
answer(ans1, ans2);
return;
}
}
}
# | 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... |