# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
628916 | flashmt | Rarest Insects (IOI22_insects) | C++17 | 0 ms | 0 KiB |
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 <bits/stdc++.h>
#include "insects.h"
using namespace std;
vector<int> findFirstOccurrences(int n, vector<int> &id)
{
vector<int> res;
for (int i = 0; i < n; i++)
if (id[i] < 0)
{
move_inside(i);
if (press_button() > 1) move_outside(i);
else
{
id[i] = size(res);
res.push_back(i);
}
}
for (int i : res)
move_outside(i);
return res;
}
int min_cardinality(int n)
{
vector<int> id(n, -1);
auto occurrences = findFirstOccurrences(n, id);
int typeCnt = size(occurrences);
int maxC = n / typeCnt;
if (maxC <= typeCnt)
{
int ans = 1;
while (1)
{
auto occ = findFirstOccurrences(n, id);
if (size(occ) != typeCnt)
return ans;
ans++;
}
}
vector<int> cnt(n);
for (int i = 0; i < n; i++)
if (id[i] < 0)
{
move_inside(i);
for (int j : occurrences)
{
move_inside(j);
if (press_button() == 2)
{
cnt[j]++;
move_outside(j);
break;
}
move_outside(j);
}
move_outside(i);
}
int ans = *max_element(begin(cnt), end(cnt)) + 1;
return ans;
}
int main() {
assert(1 == scanf("%d", &N));
color.resize(N);
in_box.assign(N, false);
std::map<int, int> type_to_color;
for (int i = 0; i < N; ++i) {
int Ti;
assert(1 == scanf("%d", &Ti));
if (type_to_color.find(Ti) == type_to_color.end()) {
int new_color = type_to_color.size();
type_to_color[Ti] = new_color;
max_occurrences.insert(0);
}
color[i] = type_to_color[Ti];
}
color_occurrences.assign(type_to_color.size(), 0);
int answer = min_cardinality(N);
int Q = *std::max_element(op_counter.begin(), op_counter.end());
printf("%d\n", answer);
printf("%d\n", Q);
return 0;
}