Submission #771341

#TimeUsernameProblemLanguageResultExecution timeMemory
771341sadsaCave (IOI13_cave)C++17
12 / 100
90 ms460 KiB
#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 &ltd) { 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...