Submission #542745

#TimeUsernameProblemLanguageResultExecution timeMemory
542745collodelCave (IOI13_cave)C++17
0 / 100
642 ms444 KiB
#include "cave.h" #include <vector> #include <iostream> using namespace std; void flip(int arr[], int start, int end) { while(start != end) { arr[start++] ^= 1; } } void unset(int arr[], int start, int end) { while(start != end) { arr[start++] = 0; } } void fix(int ans[], int ask[], int corr[], int start, int end, int n) { for(int i = 0; i < n; ++i) { if(ans[i] != -1 && ans[i] >= start && ans[i] < end) ask[i] = corr[i]; } } void exploreCave(int N) { int ans[N]; int ask[N]; int corr[N]; for(int i = 0; i < N; ++i) { ans[i] = -1, ask[i] = 0, corr[i] = 0; } for(int i = 0; i < N; ++i) { // trova se serve accendere o spegnere unset(ask, 0, N); fix(ans, ask, corr, 0, N, N); bool state = (tryCombination(ask) <= i); if(state) flip(ask, 0, N), fix(ans, ask, corr, 0, N, N); // bs int l = 0, r = N; while(r - l > 1) { int m = (l+r)/2; flip(ask, l, m); fix(ans, ask, corr, l, m, N); if(tryCombination(ask) > i) { // porta chiusa, segui [m, r) flip(ask, l, m); fix(ans, ask, corr, l, m, N); if(state) l = m; else r = m; } else { // porta aperta, segui [l, m) flip(ask, l, m); fix(ans, ask, corr, l, m, N); if(state) r = m; else l = m; } } ans[l] = i; corr[l] = state; } answer(corr, ans); }
#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...