이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/**
* Simple.
*
* Steps needed: log_2(n)
* Implementation 1
*/
#include <bits/stdc++.h>
#include "cycle.h"
int n;
int pos = 0;
// treat our initial (unknown) starting room as room 0. Provides jumping with
// absolute coordinate
inline int absolute_jump(int k) {
int steps = (k - pos + n) % n;
pos = k;
bool ans = jump(steps);
// std::cerr << k << ' ' << ans << std::endl;
return ans;
}
void escape(int _n) {
n = _n;
bool a = absolute_jump(0), b = absolute_jump(n / 2);
assert(a || b);
if (a && b) {
if (absolute_jump(1))
absolute_jump(n / 2);
else
absolute_jump(0);
return;
}
int left = 0, right = n / 2;
if (b && !a) {
std::swap(left, right);
std::swap(a, b);
}
assert(a && !b);
while (left != right) {
int dist = (right - left + n) % n;
int mid = left + (dist + 1) / 2;
if (absolute_jump(mid))
left = (mid + n) % n;
else
right = (mid - 1 + n) % n;
}
absolute_jump(left);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |