| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 629605 | flashmt | Rarest Insects (IOI22_insects) | C++17 | 1 ms | 208 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;
// return (found max cardinality, good IDs, bad IDs)
tuple<int, vector<int>, vector<int>> findFirstOccurrences(vector<int> id, int maxC, int expectedSize)
{
vector<int> good, bad;
int foundMaxC = 0;
for (int i : id)
{
if (size(good) == expectedSize)
{
bad.push_back(i);
continue;
}
move_inside(i);
int resp = press_button();
if (resp <= maxC)
{
good.push_back(i);
foundMaxC = max(foundMaxC, resp);
}
else
{
move_outside(i);
bad.push_back(i);
}
}
for (int i : good)
move_outside(i);
return {foundMaxC, good, bad};
}
int min_cardinality(int n)
{
vector<int> id(n);
iota(begin(id), end(id), 0);
auto [foundMaxC, good, bad] = findFirstOccurrences(id, 1, n);
int typeCnt = size(good);
int low = 2, high = n / typeCnt - 1, ans = 1;
id = bad;
while (low <= high)
{
int mid = (low + high) / 2;
int expectedSize = typeCnt * (mid - ans);
tie(foundMaxC, good, bad) = findFirstOccurrences(id, mid - ans, expectedSize);
if (size(good) == expectedSize)
{
ans = mid;
low = mid + 1;
id = bad;
}
else
{
high = min(mid - 1, min(int(size(good)) / typeCnt, foundMaxC) + ans);
id = good;
}
}
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... | ||||
