This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cassert>
#include <random>
#include "grader.h"
using namespace std;
mt19937 rd(31415926);
uniform_int_distribution<int> dis(0, 1);
int HC(int n)
{
int l = 1;
int r = n;
Guess(1);
int p = 1;
while (l < r) {
int z = r-l+1;
int res, side;
if (p == l) {
res = Guess(p = r), side = 0;
} else if (p == r) {
res = Guess(p = l), side = 1;
} else if (p < l) {
int q = r+(l-p);
if (q <= n) {
res = Guess(p = q);
side = 0;
} else {
Guess(p = (r <= n/2 ? r : l));
continue;
}
} else if (p > r) {
int q = l-(p-r);
if (q >= 1) {
res = Guess(p = q);
side = 1;
} else {
Guess(p = (r <= n/2 ? r : l));
continue;
}
} else {
assert(false);
}
int m = (l+r)/2;
if (side == 0) {
if (z % 2 == 0) {
if (res == 1) l = m+1;
else if (res == -1) r = m;
else assert(false);
} else {
if (res == 1) l = m+1;
else if (res == -1) r = m-1;
else l = r = m;
}
} else {
if (z % 2 == 0) {
if (res == 1) r = m;
else if (res == -1) l = m+1;
else assert(false);
} else {
if (res == 1) r = m-1;
else if (res == -1) l = m+1;
else l = r = m;
}
}
}
return l;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |