# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
628933 | flashmt | Rarest Insects (IOI22_insects) | C++17 | 162 ms | 504 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, int maxC)
{
vector<int> res;
for (int i = 0; i < n; i++)
{
move_inside(i);
if (press_button() > maxC) move_outside(i);
else res.push_back(i);
}
for (int i : res)
move_outside(i);
return res;
}
int min_cardinality(int n)
{
auto occurrences = findFirstOccurrences(n, 1);
int typeCnt = size(occurrences);
if (typeCnt <= 8)
{
vector<int> cnt(n);
for (int i = 0; i < n; i++)
{
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 = n;
for (int x : occurrences)
ans = min(ans, cnt[x] + 1);
return ans;
}
int low = 2, high = n / typeCnt, ans = 1;
while (low <= high)
{
int mid = (low + high) / 2;
auto occ = findFirstOccurrences(n, mid);
if (size(occ) == typeCnt * mid)
{
ans = mid;
low = mid + 1;
}
else high = mid - 1;
}
return ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |