Submission #831323

# Submission time Handle Problem Language Result Execution time Memory
831323 2023-08-20T04:53:34 Z definitelynotmee Rarest Insects (IOI22_insects) C++17
0 / 100
265 ms 208 KB
// First submission after reading edi
#include "insects.h"
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
using ll = long long;
using namespace std;
template<typename T>
using matrix = vector<vector<T>>;


struct Machine {
    set<int> s;

    void insert(int id){
        s.insert(id);
        move_inside(id);
    }
    void erase(int id){
        s.erase(id);
        move_outside(id);
    }

    int resp(){
        return press_button();
    }
    void clear(){
        auto it  = s.begin();
        while(it!=s.end()){
            move_outside(*it);
            it = s.erase(it);
        }
    }
};

int min_cardinality(int N) {
    mt19937 rng(time(nullptr));
    vector<int> dif;
    vector<int> resto;

    Machine m;

    for(int i = 0; i < N; i++){
        m.insert(i);
        if(m.resp() == 1){
            dif.push_back(i);
        } else m.erase(i), resto.push_back(i);
    }

    shuffle(all(dif),rng);
    shuffle(all(resto),rng);


    m.clear();

    int ini = 1, fim = N/dif.size();


    auto putless =[&](int mx){
        for(int i : resto){
            if(m.s.count(i))
                continue;
            m.insert(i);
            if(m.resp() > mx)
                m.erase(i);
        }
    };

    int last = -1;

    while(ini!=fim){
        int mid = (ini+fim)>>1;

        // cerr << "mid = " << mid << '\n';
        
        if(mid < last){
            vector<int> newresto;

            for(int i : m.s)
                newresto.push_back(i);
            swap(resto,newresto);
            m.clear();
        }
        
        putless(mid-1);

        bool ok = 1;

        for(int i : dif){
            m.insert(i);
            ok&= m.resp() == mid;
            m.erase(i);
        }

        if(ok)
            ini = mid;
        else fim = mid-1;
        last = mid;
    } 
    return ini;

    

}
# Verdict Execution time Memory Grader output
1 Incorrect 225 ms 208 KB Too many queries.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 225 ms 208 KB Too many queries.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 265 ms 208 KB Too many queries.
2 Halted 0 ms 0 KB -