#include <bits/stdc++.h>
#include "insects.h"
using namespace std;
int AJOUTER = 0;
int RETIRER = 1;
bool superiorK(int k, int nbTypes, vector<bool>& ensemble, int N, int taille) {
vector<int> objets;
for (int i = 0; i < N; i++) {
if (!ensemble[i]) {
move_inside(i);
if (press_button() > k) {
move_outside(i);
}
else {
ensemble[i] = true;
objets.push_back(i);
taille++;
}
}
}
if (taille < k*nbTypes) {
for (int i : objets) {
move_outside(i);
ensemble[i] = false;
}
return false;
}
return true;
}
int min_cardinality(int N) {
int nbTypes = 0;
for (int i = 0; i < N; i++) {
move_inside(i);
if (press_button() != 1) {
move_outside(i);
}
else {
nbTypes++;
}
}
vector<bool> ensemble(N, false);
int debut = 1, fin = nbTypes;
int taille = 0;
while (debut < fin) {
int mid = (debut+fin)/2;
if (superiorK(mid, nbTypes, ensemble, N, taille)) {
if (debut+1 == fin) break;
debut = mid+1;
taille = mid*nbTypes;
}
else {
fin = mid;
}
}
return debut;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |