답안 #1075607

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1075607 2024-08-26T07:58:00 Z kilikuma 드문 곤충 (IOI22_insects) C++17
컴파일 오류
0 ms 0 KB
#include "insects.h"

using namespace std; 

vector<bool> cur(2000, false);

void trash() {
  for (int i = 0; i < 2000; i ++) {
    if (cur[i]) {
      enleve(i);
    }
  }
}

void enleve(int k) {
  move_outside(k);
  cur[k] = false;
}

void ajoute(int k) {
  move_inside(k);
  cur[k] = true;
}

int nbElem() {
  int k = 0;
  for (int i = 0; i < 2000; i ++) {
    if (cur[i]) {
      k ++;
    }
  }
  return k;
}

int unif(int n) {
  for (int i = 0; i < n; i ++) {
    ajoute(i);
    if (press_button() >= 2) {
      enleve(i);
    }
  }
  int x = nbElem();
  trash();
  return x;
}

bool ok(int borne, int cb, int n) {
  for (int i = 0; i < n; i ++) {
    ajoute(i);
    if (press_button() >= (borne + 1)) {
      enleve(i);
    }
  }

  int x = nbElem();
  trash();

  if (x == (cb * borne)) {
    return true;
  }
  else {
    return false;
  }
}

int min_cardinality(int N) {

  int l = 1, r = N / 2;

  int nbDist = unif(N);

  while (r - l > 1) {
    int mid = (l + r) / 2;
    if (ok(mid, nbDist, N)) {
      l = mid;
    }
    else {
      r = mid;
    }
  }

  if (ok(r, nbDist, N)) {
    return r;
  }
  else {
    return l;
  }

  return 0;
}

Compilation message

insects.cpp:5:1: error: 'vector' does not name a type
    5 | vector<bool> cur(2000, false);
      | ^~~~~~
insects.cpp: In function 'void trash()':
insects.cpp:9:9: error: 'cur' was not declared in this scope
    9 |     if (cur[i]) {
      |         ^~~
insects.cpp:10:7: error: 'enleve' was not declared in this scope
   10 |       enleve(i);
      |       ^~~~~~
insects.cpp: In function 'void enleve(int)':
insects.cpp:17:3: error: 'cur' was not declared in this scope
   17 |   cur[k] = false;
      |   ^~~
insects.cpp: In function 'void ajoute(int)':
insects.cpp:22:3: error: 'cur' was not declared in this scope
   22 |   cur[k] = true;
      |   ^~~
insects.cpp: In function 'int nbElem()':
insects.cpp:28:9: error: 'cur' was not declared in this scope
   28 |     if (cur[i]) {
      |         ^~~