이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "cave.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using ii = tuple<int, int>;
using vii = vector<ii>;
void flip(vi &levers, vb &lv, int l, int r) {
for (; l <= r; ++l) {
if (!lv[l]) levers[l] = 1-levers[l];
}
}
int findCombo(int index, vi &levers, vb &lv) {
int l = 0, r = lv.size()-1;
int door, mid;
door = tryCombination(levers.data());
if (door != index) {
flip(levers, lv, l, r);
}
while (l != r) {
if (r-l==1) {
flip(levers, lv, l, l);
door = tryCombination(levers.data());
if (door == index) { // no change, so right side is correct
l = r;
} else { // change, ans=l, flip back
r = l;
flip(levers, lv, l, l);
}
break;
}
mid = (l+r)/2;
flip(levers, lv, mid, r); // flip right
door = tryCombination(levers.data());
if (door == index) { // nothing changed, so check left half
r = mid-1;
} else { // door changed, so flip back and check right half further
flip(levers, lv, mid, r);
l = mid;
}
}
flip(levers, lv, l, l); // open door
lv[l] = 1;
return l;
}
void exploreCave(int N) {
vi levers(N, 0);
vi ltd(N, -1);
vb lv(N, false);
for (int lever = 0; lever < N; ++lever) {
ltd[lever] = findCombo(lever, levers, lv);
}
answer(levers.data(), ltd.data());
}
# | 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... |