#include "grader.h"
#include <bits/stdc++.h>
using namespace std;
int HC(int N){
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int l = 1, r = N;
int lst = 1;
Guess(lst);
for(int i=0;i<100;i++) {
if(l == r) return l;
int curr = (l + r) / 2;
if(curr == lst) {
while(curr == lst) {
curr = uniform_int_distribution<int>(l, r)(rng);
}
}
int q = Guess(curr);
//cout<<i<<" - Previous was: "<<lst<<"\n";
//cout<<l<<", "<<r<<" - "<<curr<<" --> "<<q<<"\n";
if(curr < lst) {
if(q == -1) {
int sz = (lst - curr + 1) / 2;
int cl = lst - sz + 1;
int cr = N;
l = max(l,cl);
r = min(r,cr);
}
else if(q == 0) {
int mid = (lst + curr) / 2;
return mid;
}
else {
int sz = (lst - curr + 1) / 2;
int cl = 1;
int cr = curr + sz - 1;
l = max(l,cl);
r = min(r,cr);
}
}
else if(curr > lst) {
if(q == -1) {
int sz = (curr - lst + 1) / 2;
int cl = 1;
int cr = lst + sz - 1;
l = max(l,cl);
r = min(r,cr);
}
else if(q == 0) {
int mid = (lst + curr) / 2;
return mid;
}
else {
int sz = (curr - lst + 1) / 2;
int cl = curr - sz + 1;
int cr = N;
l = max(l,cl);
r = min(r,cr);
}
}
lst = curr;
}
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
867 ms |
1400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
869 ms |
1400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
869 ms |
1376 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
8252 ms |
8192 KB |
Output is partially correct - alpha = 0.222222222222 |