#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) curr++;
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 |
56 ms |
1272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
1272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
58 ms |
1400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
1006 ms |
8312 KB |
Output is partially correct - alpha = 0.400000000000 |