답안 #784973

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
784973 2023-07-16T20:43:18 Z Sam_a17 커다란 상품 (IOI17_prize) C++17
0 / 100
7 ms 4308 KB
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define ld long double
#define ll long long

#define sz(x) (int((x).size()))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define uniq(x) x.resize(unique(all(x)) - x.begin());
#define lb lower_bound
#define ub upper_bound

// for random generations
mt19937 myrand(chrono::steady_clock::now().time_since_epoch().count());
// mt19937 myrand(131);

std::vector<int> ask(int i);
const int N = 2e5 + 10;
pair<int, int> a[N];
int used[N];

int find_best(int n) {
  memset(used, -1, sizeof(used));

  int mxi = 0;
  for(int i = 0; i < 500; i++) {
    int cur = myrand() % n;
    while (used[cur] == 1) {
      cur = myrand() % n;
    }
    
    auto u = ask(cur);

    a[cur].first = u[0];
    a[cur].second = u[1];
    
    if((u[0] + u[1]) == 0) {
      return cur;
    }

    mxi = max(mxi, u[0] + u[1]);
    used[cur] = 1;
  }

  if(n >= 150000) {
    assert(mxi >= 2);
  }

  for(int i = 0; i < n; i++) {
    int ina = i, inb = n - 1, answ = i;
    int lx, rx;
    if(used[i] != -1) {
      lx = a[i].first;
      rx = a[i].second;
    } else {
      auto u = ask(i);

      a[i].first = u[0];
      a[i].second = u[1];

      lx = u[0], rx = u[1];
      used[i] = 1;
    }

    if((lx + rx) == 0) {
      return i;
    }

    if((lx + rx) != mxi) {
      continue;
    }

    while(ina <= inb) {
      int mid = (ina + inb) / 2;
      int l = 0, r = 0;
      if(used[mid] != -1) {
        l = a[mid].first;
        r = a[mid].second;
      } else {
        auto u = ask(mid);

        a[mid].first = u[0];
        a[mid].second = u[1];

        l = u[0], r = u[1];
        used[i] = 1;
      }

      if((l + r) == 0) {
        return mid;
      }

      if(l == lx && (l + r) == (lx + rx)) {
        answ = mid;
        ina = mid + 1;
      } else {
        inb = mid - 1;
      }
    }

    i = answ;
  }

  // xd
  return -1;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 7 ms 4276 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 4308 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -