Submission #542741

#TimeUsernameProblemLanguageResultExecution timeMemory
542741collodelCave (IOI13_cave)C++17
0 / 100
2080 ms340 KiB
#include "cave.h" #include <vector> 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] >= start && ans[i] < end) ask[ans[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(l != r) { int m = (l+r)/2; flip(ask, l, m); fix(ans, ask, corr, l, m, N); if(tryCombination(ask) > i) { // porta aperta, segui [l, m) r = m; } else { // porta chiusa, segui [m, r) l = m; } flip(ask, l, m); fix(ans, ask, corr, l, m, N); } 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...