Submission #243528

#TimeUsernameProblemLanguageResultExecution timeMemory
243528AlexPop28Cave (IOI13_cave)C++11
100 / 100
906 ms632 KiB
#include <bits/stdc++.h> #include "cave.h" using namespace std; void exploreCave(int n) { auto Ask = [&](int state[]) { int ans = tryCombination(state); if (ans == -1) ans = n; return ans; }; int *state = new int[n]; int *door = new int[n]; for (int i = 0; i < n; ++i) state[i] = 0, door[i] = -1; auto Flip = [&](int fin) { for (int i = 0; i <= fin; ++i) if (door[i] == -1) state[i] ^= 1; }; for (int i = 0; i < n; ++i) { int pos = Ask(state); if (pos > i) { Flip(n - 1); } int lo = 0, hi = n - 1, ans = -1; while (lo <= hi) { int mid = lo + (hi - lo) / 2; Flip(mid); pos = Ask(state); Flip(mid); if (pos > i) { ans = mid; hi = mid - 1; } else { lo = mid + 1; } } door[ans] = i; state[ans] ^= 1; } assert(tryCombination(state) == -1); answer(state, door); }
#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...