# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
815163 | JakobZorz | Rarest Insects (IOI22_insects) | C++17 | 149 ms | 544 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"insects.h"
#include<iostream>
#include<vector>
#include<set>
using namespace std;
set<int>inside;
int n,distinct;
int low_bound,high_bound;
int c_press_button(){
return press_button();
}
void c_move_inside(int a){
inside.insert(a);
move_inside(a);
}
void c_move_outside(int a){
inside.erase(a);
move_outside(a);
}
void check(int c){
for(int i=0;i<n;i++){
c_move_inside(i);
if(c_press_button()>c)
c_move_outside(i);
}
bool res=inside.size()==c*distinct;
if(res){
low_bound=c;
high_bound=n;
}else{
low_bound=0;
high_bound=c;
}
vector<int>inside_vec={inside.begin(),inside.end()};
for(int i:inside_vec)
c_move_outside(i);
}
int get_distinct(){
for(int i=0;i<n;i++){
c_move_inside(i);
if(c_press_button()>1)
c_move_outside(i);
}
int res=inside.size();
vector<int>inside_vec={inside.begin(),inside.end()};
for(int i:inside_vec)
c_move_outside(i);
return res;
}
int min_cardinality(int N){
n=N;
distinct=get_distinct();
if(distinct>n/2)
return 1;
if(distinct==1)
return n;
int l=1,r=n/distinct+1;
while(l<r-1){
int m=(l+r)/2;
check(m);
l=max(low_bound,l);
r=min(high_bound,r);
}
return l;
}
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... |