답안 #957376

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
957376 2024-04-03T15:11:58 Z kilkuwu 커다란 상품 (IOI17_prize) C++17
0 / 100
6 ms 5412 KB
#include "prize.h"
#include <bits/stdc++.h>

int find_best(int n) {
  std::vector<std::vector<int>> dp(n);

  auto query = [&](int i) -> std::vector<int> {
    if (dp[i].size()) return dp[i];
    return dp[i] = ask(i);
  };

  const int B = 500;
  if (n <= B) {
    for (int i = 0; i < n; i++) {
      auto res = query(i);
      if (res[0] + res[1] == 0) {
        return i;
      }
    }
    return 0;
  }

  int mx = 0;
  for (int i = 0; i < B; i++) {
    auto res = query(i);
    if (res[0] + res[1] == 0) return i;
    mx = std::max(mx, res[0] + res[1]);
  }

  int p = -1;
  for (int done = 0; done < mx; done++) {
    p++;

    int l = p;
    int r = n - 1;

    while (l < r) {
      int m = (l + r) / 2;

      auto res = query(m);

      if (res[0] + res[1] == 0) return m;

      if (res[0] + res[1] < mx || (res[0] > done)) {
        r = m;
      } else {
        l = m + 1;
      }
    }

    p = l;
  }

  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5156 KB Output is correct
2 Correct 3 ms 5152 KB Output is correct
3 Correct 5 ms 5400 KB Output is correct
4 Incorrect 4 ms 5152 KB answer is not correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5404 KB Output is correct
2 Correct 5 ms 5148 KB Output is correct
3 Correct 6 ms 5412 KB Output is correct
4 Incorrect 4 ms 5404 KB answer is not correct
5 Halted 0 ms 0 KB -