#include "grader.h"
#include<cassert>
#include<cstdio>
int guess(int a, int b) {
Guess(a);
return Guess(b);
}
int HC(int n){
int l = 1, r = n;
int cnt = 0;
while(r - l > 6) {
int ans = guess(l, r);
if(!ans) {/*assert(cnt < 18);*/ return (l+r) >> 1;}
if(ans == 1) l = (l+r+1) >> 1;
else r = (l+r-1) >> 1;
cnt += 2;
}
// assert(cnt <= 14);
// printf("l == %d r == %d\n", l, r);
// printf("cnt == %d\n", cnt);
if(r == l) return l;
if(r-l == 1)
return guess(l, r)==1?r:l;
if(r - l == 2) {
int ans = guess(l, r);
return ans==1?r:ans==0?l+1:l;
}
if(r - l == 3) {
int ans = guess(l, r-1);
if(ans == 0) return l+1;
if(ans == -1) return l;
if(Guess(r) == 1) return r;
// printf("%d\n", cnt+3);
return r-1;
}
// Resolve um intervalo de 5 com 3 movimentos
if(r - l == 4) {
int ans = guess(l, l+2);
if(ans == -1) return l;
if(ans == 0) return l+1;
ans = Guess(r);
return ans==-1?l+2:ans==0?l+3:r;
}
// 4 mov
if(r - l == 5) {
int ans = guess(l, l+2);
if(ans == -1) return l;
if(ans == 0) return l+1;
l = l+2;
ans = Guess(l+2);
if(ans == -1) return l;
if(ans == 0) return l+1;
l = l+2;
ans = Guess(l+1);
return ans==1?l+1:l;
}
// 4 mov
if(r - l == 6) {
int ans = guess(l, l+2);
if(ans == -1) return l;
if(ans == 0) return l+1;
l = l+2;
ans = Guess(l+2);
if(ans == -1) return l;
if(ans == 0) return l+1;
l = l+2;
ans = Guess(l+2);
if(ans == -1) return l;
if(ans == 0) return l+1;
return l+2; // l+2 == r
}
// Resolve um intervalo de 8 com 4 movimentos
// if(r - l == 7) {
// int ans = guess(l+2, l+4);
// if(ans == 1) {
// l+=4;
// assert(l+2 == r-1);
// ans = Guess(r-1);
// if(ans == 0) return l+1;
// if(ans == -1) return l;
// if(Guess(r) == 1) return r;
// return r-1;
// }
// if(!ans) return l+3;
// ans = guess(l, l+2);
// if(ans == 1) return l+2;
// if(ans == -1) return l;
// return l+1;
// }
assert(0);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
1408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
1280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
23 ms |
1280 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
753 ms |
8260 KB |
Output is partially correct - alpha = 0.068965517241 |