#include "insects.h"
#include <iostream>
#include <vector>
using namespace std;
bool box[2002];
int currentMax = 0;
int inBox = 0;
int n;
void add_until_group_amount(int num) {
for(int i = 0; i < n; i++) {
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(int num) {
for(int i = 0; i < n; i++) {
if (!box[i]) continue;
move_outside(i);
box[i] = false;
inBox--;
}
}
int min_cardinality(int N) {
vector<int> groups(N);
n = N;
int groupCount = 0;
int returnVal;
for(int i = 0; i < N; i++) {
move_inside(i);
returnVal = press_button();
if (returnVal > 1) { move_outside(i); continue; }
box[i] = true;
inBox++;
groupCount++;
}
int upper = 1 + N/groupCount, lower = 0;
// cout << "groupCount, upper: " << groupCount << " " << upper << "\n";
int mid;
while (upper-lower > 0) {
mid = (upper-lower+1)/2;
// cout << "\n-----\n" << lower+mid << "\n------\n";
add_until_group_amount(lower+mid);
if (inBox/groupCount == lower+mid) {
lower += mid;
} else {
upper = lower+mid-1;
remove_some(lower+mid);
}
}
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... |