제출 #1361788

#제출 시각아이디문제언어결과실행 시간메모리
1361788kunzaZa183커다란 상품 (IOI17_prize)C++20
20 / 100
1060 ms416 KiB
#include "prize.h"
#include <bits/stdc++.h>
using namespace std;

int find_best(int n) {
  int mk = min((int)sqrt(n) + 5, n);
  int mx = -1;
  int n1, n2;
  int lst = -1;
  int ct = 0;
  for (int i = 0; i < mk; i++) {
    auto vi = ask(i);
    ct++;
    if (ct >= 9500) {
      while (1) {
      }
    }
    if (vi[0] + vi[1] == 0) {
      return i;
    }
    if (vi[0] + vi[1] >= mx) {
      n1 = vi[0], n2 = vi[1];
      mx = vi[0] + vi[1];
      lst = i;
    }
  }

  while (1) {
    int l = lst + 1, r = n - 1;
    while (l < r) {
      int mid = (l + r) / 2;

      auto vi = ask(mid);
      ct++;

      if (ct >= 9500) {
        while (1) {
        }
      }

      if (vi[0] + vi[1] == mx) {
        if (vi[0] > n1) {
          r = mid - 1;
        } else {
          l = mid + 1;
        }
      } else {
        r = mid;
      }
    }

    auto vi = ask(l);
    ct++;
    if (ct >= 9500) {
      while (1) {
      }
    }
    if (vi[0] + vi[1] == 0) {
      return l;
    }

    lst = l;
    while (lst < n) {
      auto vi = ask(lst);
      ct++;
      if (ct >= 9500) {
        while (1) {
        }
      }
      if (vi[0] + vi[1] == mx) {
        n1 = vi[0], n2 = vi[1];
        break;
      } else if (vi[0] + vi[1] == 0) {
        return lst;
      }
      lst++;
    }
  }
}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…