제출 #771346

#제출 시각아이디문제언어결과실행 시간메모리
771346sadsa동굴 (IOI13_cave)C++17
12 / 100
184 ms412 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 index, vi &levers, vb &lv) { int l = 0, r = lv.size()-1; int door, mid; door = tryCombination(levers.data()); if (door != index) { flip(levers, lv, l, r); } while (l != r) { if (r-l==1) { flip(levers, lv, 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, lv, l, l); } break; } mid = (l+r)/2; flip(levers, lv, 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, lv, mid, r); l = mid; } } flip(levers, lv, l, l); // open door lv[l] = 1; return l; } void exploreCave(int N) { vi levers(N, 0); vi ltd(N, -1); vb lv(N, false); for (int lever = 0; lever < N; ++lever) { ltd[lever] = findCombo(lever, levers, lv); } 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...