이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |