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;
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, int l, int r) {
for (; l <= r; ++l) {
levers[l] = 1-levers[l];
}
}
int findCombo(int index, vi &levers, vi <d) {
int l = index, r = ltd.size()-1;
int door, mid;
door = tryCombination(levers.data());
if (door != index) {
flip(levers, l, r);
}
while (l != r) {
if (r-l==1) {
flip(levers, 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, l, l);
}
break;
}
mid = (l+r)/2;
flip(levers, 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, mid, r);
l = mid;
}
}
flip(levers, l, l); // open door
return l;
}
void exploreCave(int N) {
vi levers(N, 0);
vi ltd(N, -1);
for (int lever = 0; lever < N; ++lever) {
ltd[lever] = findCombo(lever, levers, ltd);
}
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... |