# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
859412 | kim | Rarest Insects (IOI22_insects) | C++17 | 41 ms | 1816 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<bits/stdc++.h>
using namespace std;
#define in move_inside
#define press press_button
#define out move_outside
set<int> mp,mp2,mp3;
int n,p;
bool check(int k1){
stack<int> st;
for(int i=0;i<n;++i){
if(mp.size()==p*k1) break;
if(mp.count(i)) continue;
if(mp3.count(i)) continue;
in(i);
if(press()>k1) out(i);
else mp.insert(i),st.push(i);
}
if(mp.size()==p*k1){
for(auto &e:mp) if(mp2.count(e)) mp2.erase(e);
return 1;
}
stack<int> st2;
for(auto &e:mp2){
if(!mp.count(e)) st2.push(e);
}
while(!st2.empty()){
mp2.erase(st2.top());
mp3.insert(st2.top());
st2.pop();
}
while(st.size()){
mp.erase(st.top());
out(st.top());
st.pop();
}
return 0;
}
int min_cardinality(int N){
n=N;
for(int i=0;i<n;++i){
in(i);
if(press()>1) out(i),mp2.insert(i);
else mp.insert(i);
}
p=mp.size();
int l=1,r=n/p;
while(l<r){
if(r==l+1){
if(check(r)) return r;
return l;
}
if(r==l+2){
if(check(r)) return r;
if(check(l+1)) return l+1;
return l;
}
int sz=(r-l)/3;
int mid1=l+sz;
int mid2=r-sz;
if(check(mid2)) l=mid2;
else if(check(mid1)) l=mid1,r=mid2-1;
else r=mid1-1;
}
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... |