#include "grader.h"
int HC(int N)
{
int low = 1;
int high = N;
int guess = high; // Primeiro palpite é N
int previous_guess = 0;
while (low < high)
{
int response = Guess(guess);
if (response == 1)
{
if (previous_guess > guess)
high = (guess + high) / 2;
if (previous_guess < guess)
low = (guess + low) / 2;
}
else if (response == -1)
{
if (previous_guess > guess)
low = (guess + low) / 2;
if (previous_guess < guess)
high = (guess + high) / 2;
}
previous_guess = guess;
if (response == 0 && guess == previous_guess) // Casos especiais
guess = guess + 1;
if (response != 0) // Padrão
guess = (low + high) / 2;
}
return low;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
10015 ms |
1236 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
10034 ms |
1276 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
10043 ms |
1236 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
10006 ms |
24296 KB |
Time limit exceeded |