Submission #831272

# Submission time Handle Problem Language Result Execution time Memory
831272 2023-08-20T03:37:22 Z definitelynotmee Rarest Insects (IOI22_insects) C++17
0 / 100
279 ms 336 KB
#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 = ceil((ini+fim)*0.4);
        
        if(mid < last)
            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 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Incorrect 228 ms 208 KB Too many queries.
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Incorrect 228 ms 208 KB Too many queries.
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Incorrect 279 ms 208 KB Too many queries.
7 Halted 0 ms 0 KB -