#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;
int p = 0;
while (l < r) {
if (p != l && p != r) {
if (dis(rd) == 0) {
Guess(l);
p = l;
} else {
Guess(r);
p = r;
}
}
int z = r-l+1;
int m = (l+r)/2;
if (p == l) {
int res = Guess(r);
p = r;
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 {
int res = Guess(l);
p = l;
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 |
1 |
Correct |
46 ms |
1272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
1272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
1272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1191 ms |
8312 KB |
Output is partially correct - alpha = 0.142857142857 |