Submission #771350

#TimeUsernameProblemLanguageResultExecution timeMemory
771350sadsaCave (IOI13_cave)C++17
100 / 100
247 ms416 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, vb &lv, int l, int r) { for (; l <= r; ++l) { if (!lv[l]) levers[l] = 1-levers[l]; } } int findCombo(int doorToFind, vi &levers, vb &lv) { int l = 0, r = lv.size()-1; int door, mid; door = tryCombination(levers.data()); if (door != doorToFind) { flip(levers, lv, l, r); } while (l != r) { if (r-l==1) { flip(levers, lv, l, l); door = tryCombination(levers.data()); if (door == doorToFind) { // 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 == doorToFind) { // 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] = true; return l; } void exploreCave(int N) { vi levers(N, 0); vi ltd(N, -1); vb lv(N, false); for (int door = 0; door < N; ++door) { ltd[findCombo(door, levers, lv)] = door; } 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...