#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
867 ms |
1388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
866 ms |
1272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
864 ms |
1400 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
8151 ms |
8184 KB |
Output is partially correct - alpha = 0.222222222222 |