Submission #1082556

# Submission time Handle Problem Language Result Execution time Memory
1082556 2024-08-31T15:31:51 Z aaaaaarroz Hotter Colder (IOI10_hottercolder) C++17
Compilation error
0 ms 0 KB
#include "grader.h"

int HC(int N) {
    int left = 1, right = N;
    int last_guess = (left + right) / 2;

    // Make the first guess
    Guess(last_guess);
    int last_distance = abs(last_guess - GuessResult());  // Distance to target (initially unknown)

    while (left <= right) {
        int mid = (left + right) / 2;
        Guess(mid);

        int current_distance = abs(mid - GuessResult());
        if (Guess(mid) == 0) {
            return mid; // The correct number is found
        }
        
        if (Guess(mid) == 1) { // Hotter
            if (current_distance < last_distance) {
                left = mid + 1;
            } else {
                right = mid - 1;
            }
        } else { // Colder
            if (current_distance > last_distance) {
                left = mid + 1;
            } else {
                right = mid - 1;
            }
        }
        
        last_distance = current_distance;
        last_guess = mid;
    }

    return -1; // In case something goes wrong
}

Compilation message

hottercolder.cpp: In function 'int HC(int)':
hottercolder.cpp:9:42: error: 'GuessResult' was not declared in this scope
    9 |     int last_distance = abs(last_guess - GuessResult());  // Distance to target (initially unknown)
      |                                          ^~~~~~~~~~~
hottercolder.cpp:9:25: error: 'abs' was not declared in this scope
    9 |     int last_distance = abs(last_guess - GuessResult());  // Distance to target (initially unknown)
      |                         ^~~