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 min_cardinality(int N)
{
int num_insects = 0;
set<int> s;
for(int i = 0; i < N; i++)
{
// cout << "moving inside[1]: " << i << endl;
move_inside(i);
s.insert(i);
num_insects++;
if(press_button() == 2)
{
// cout << "moving outside[1]: " << i << endl;
move_outside(i);
s.erase(i);
num_insects--;
}
}
// cout << "num_insects = " << num_insects << endl;
int l = 1, r = N / num_insects, ans = r;
bool flag = true;
while(l <= r)
{
int mid = (l + r) / 2;
// cout << "mid = " << mid << endl;
// cout << "s.size() = " << s.size() << endl;
if(!flag)
{
for(auto i: s)
{
// cout << "i = " << i << endl;
// cout << "moving outside[2]: " << i << endl;
move_outside(i);
}
s.clear();
}
// cout << "hello!" << endl;
int current_insects = s.size();
for(int i = 0; i < N; i++)
{
if(s.count(i)) continue;
// cout << "moving inside[3]: " << i << endl;
move_inside(i);
s.insert(i);
current_insects++;
if(press_button() > mid)
{
// cout << "moving outside[3]: " << i << endl;
move_outside(i);
s.erase(i);
current_insects--;
}
if(current_insects == mid * num_insects)
{
break;
}
}
// cout << "current_insects = " << current_insects << endl;
if(current_insects == mid * num_insects)
{
ans = mid;
l = mid + 1;
flag = true;
}
else
{
r = mid - 1;
flag = false;
}
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |