Submission #1025069

#TimeUsernameProblemLanguageResultExecution timeMemory
1025069vjudge1Rarest Insects (IOI22_insects)C++17
47.51 / 100
179 ms996 KiB
#include "insects.h"
#include <bits/stdc++.h>

#define ll long long
#define sz(s) (int)s.size()
#define pb push_back
#define in insert
#define lb lower_bound
#define ub upper_bound

using namespace std;

const int MAX=2e5+10;

int n;
vector<int> a;
set<int> st;

bool check(int m){
    st.clear();
    for(int x:a)st.in(x);
    vector<int> vec;
    for(int i=0;i<n;i++){
        if(!st.count(i)){
            move_inside(i);
            if(press_button()>m){
                move_outside(i);
            }
            else{
                st.in(i);
                vec.pb(i);
            }
        }
    }
    for(int x:vec)move_outside(x);
    // if(sz(st)!=m*sz(a)){
    //     for(int x:vec)move_outside(x);
    // }
    // cout<<m<<" "<<sz(st)<<" "<<m*sz(a)<<"\n";
    // 0 33
    // 1 41
    // 2 40
    // 3 41
    // 4 45
    return (sz(st)==m*sz(a));
}

int min_cardinality(int N){
    n=N;
    for(int i=0;i<N;i++){
        move_inside(i);
        if(press_button()==2){
            move_outside(i);
        }
        else{
            a.pb(i);
        }
    }
    // check(32);
    // check(33);
    // check(34);
    // return 0;
    // cout<<sz(a)<<"\n";
    int l=1,r=N/sz(a),res=1;
    while(l<=r){
        int m=(l+r)/2;
        if(check(m)){
            l=m+1;
            res=m;
        }
        else r=m-1;
    }
    return res;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...