QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#398105#4565. Rarest Insectshos_lyricCompile Error//C++14947b2024-04-24 22:14:232024-04-24 22:14:23

Judging History

你现在查看的是最新测评结果

  • [2024-04-24 22:14:23]
  • 评测
  • [2024-04-24 22:14:23]
  • 提交

answer

#include "insects.h"

#include <vector>
using std::vector;

#define push move_inside
#define pop move_outside
#define get press_button

// us -> vs, ws
vector<int> us, vs, ws;
void go(int thr) {
  vs.clear();
  ws.clear();
  for (const int u : us) {
    push(u);
    if (get() <= thr) {
      vs.push_back(u);
    } else {
      pop(u);
      ws.push_back(u);
    }
  }
}

int min_cardinality(int N) {
  us.resize(N);
  for (int u = 0; u < N; ++u) us[u] = u;
  
  go(1);
  const int K = vs.size();
  us.swap(ws);
  
  assert(K >= 3);
  
  // keep inside: lo insects of each type
  int lo = 1, hi = N / K + 1;
  for (; lo + 1 < hi; ) {
    const int mid = (lo + hi) / 2;
    go(mid);
    if ((int)vs.size() >= K * (mid - lo)) {
      lo = mid;
      us.swap(ws);
    } else {
      hi = lo + (int)vs.size() / K + 1;
      for (const int v : vs) pop(v);
      us.swap(vs);
    }
  }
  return lo;
}

詳細信息

implementer.cpp:8:8: warning: inline variables are only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
    8 | static inline constexpr int kMaxQueries = 40000;
      |        ^~~~~~
answer.code: In function ‘int min_cardinality(int)’:
answer.code:34:3: error: ‘assert’ was not declared in this scope
   34 |   assert(K >= 3);
      |   ^~~~~~
answer.code:4:1: note: ‘assert’ is defined in header ‘<cassert>’; did you forget to ‘#include <cassert>’?
    3 | #include <vector>
  +++ |+#include <cassert>
    4 | using std::vector;