제출 #1073438

#제출 시각아이디문제언어결과실행 시간메모리
1073438vjudge1커다란 상품 (IOI17_prize)C++17
20 / 100
1 ms600 KiB
#include "prize.h"
#include <cassert>
// #include <iostream>
#include <vector>

using namespace std;

int find_best(int n) {
  int high = n; // not possible
  int low = 0;  // possible

  while (high - low > 1) {
    int mid = low + (high - low) / 2;

    vector<int> res = ask(mid);
    int left = res.at(0);
    int right = res.at(1);

    assert(left + right <= 1);

    if (left + right == 0) {
      high = mid + 1; // not possible, because 'current' is the answer
      low = mid;      // possible
    } else if (left == 1) {
      high = mid; // not possible, because answer is to the left
    } else if (right == 1) {
      low = mid + 1; // possible, because answer is to the right
    }
  }

  return low;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...