This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "insects.h"
#include <bits/stdc++.h>
using namespace std;
int ceil(int n, int r) {
return n/r + n%r;
}
// Get an array of insects, such that all their types are distinct
vector<int> getRepresentatives(int N) {
vector<int> inMachine;
for (int i = 0; i < N; ++i) {
move_inside(i);
if (press_button() > 1) {
move_outside(i);
} else {
inMachine.push_back(i);
}
}
for (int v : inMachine) move_outside(v);
return inMachine;
}
// find the max k such that all types have at least >= k insects
// in a query, we can check if all types have at least >= k' insects
int getAllLowerBound(vector<int> ids, int B, int answerMax) {
if (answerMax == 0) return 0; // base case
/*
printf("GALB([");
for (int v : ids) printf("%d ", v);
printf("], %d, %d)\n",B, answerMax);
*/
int mid = answerMax - answerMax / 3; // this is a guess
// printf("checking if min >= %d\n", mid);
set<int> inMachine;
for (int v : ids) {
move_inside(v);
if (press_button() > mid) {
// this is the >midth insect of its type, keep it out
move_outside(v);
} else {
inMachine.insert(v);
}
}
// printf("%lu in machine\n", inMachine.size());
for (int v : inMachine) move_outside(v);
if (inMachine.size() >= mid * B) {
// check success; do a GALB on the rest now
vector<int> remaining;
for (int v : ids) if (inMachine.count(v) == 0) remaining.push_back(v);
return mid + getAllLowerBound(remaining, B, answerMax - mid);
} else {
// check fail; do a GALB with a lower ansMax
return getAllLowerBound(ids, B, mid - 1);
}
}
int min_cardinality(int N) {
vector<int> reps = getRepresentatives(N);
int B = reps.size(); // B is the number of types
// printf("! %d unique types\n", B);
vector<int> insects(N);
iota(begin(insects), end(insects), 0);
return getAllLowerBound(insects, B, ceil(N, B));
}
Compilation message (stderr)
insects.cpp: In function 'int getAllLowerBound(std::vector<int>, int, int)':
insects.cpp:49:26: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
49 | if (inMachine.size() >= mid * B) {
| ~~~~~~~~~~~~~~~~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |