#include "insects.h"
#include <iostream>
#include <vector>
using namespace std;
bool box[2002];
int currentMax = 0;
int inBox = 0;
int n;
vector<int> currentArray;
void add_until_group_amount(int num) {
    for (auto i : currentArray) {
        if(box[i]) continue;
        move_inside(i);
        int returnVal = press_button();
        if (returnVal > num) { move_outside(i); continue; }
        box[i] = true;
        inBox++;
    }
}
void remove_some() {
    currentArray.clear();
    for(int i = 0; i < n; i++) {
        if (!box[i]) continue;
        move_outside(i);
        box[i] = false;
        inBox--;
        currentArray.push_back(i);
    }
}
int min_cardinality(int N) {
    vector<int> groups(N);
    n = N;
    int groupCount = 0;
    int returnVal;
    for(int i = 0; i < N; i++) {
        currentArray.push_back(i);
        move_inside(i);
        returnVal = press_button();
        if (returnVal > 1) { move_outside(i); continue; }
        box[i] = true;
        inBox++;
        groupCount++;
    }
    int upper = N/groupCount, lower = 0;
    // cout << "groupCount, upper: " << groupCount << " " << upper << "\n";
    int mid;
    while (upper-lower > 0) {
        mid = (upper-lower+1)/2;
        add_until_group_amount(lower+mid);
        if (inBox/groupCount == lower+mid) {
            lower += mid;
        } else {
            upper = lower+mid-1;
            remove_some();
        }
    }
    return lower;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |