Submission #736440

#TimeUsernameProblemLanguageResultExecution timeMemory
736440puppyRarest Insects (IOI22_insects)C++17
86.52 / 100
112 ms552 KiB
#include "insects.h"
#include <vector>
#include <iostream>
using namespace std;
pair<vector<int>, int> check(vector<int> vc, int tst)
{
    vector<bool> u(vc.size());
    vector<int> toremove;
    for (int i = 0; i < (int)vc.size(); i++) {
        move_inside(vc[i]);
        if (press_button() > tst) {
            move_outside(vc[i]);
            u[i] = true;
        }
        else toremove.push_back(vc[i]);
    }
    for (int i:toremove) move_outside(i);
    toremove.clear();
    int cnt = 0;
    for (int i = 0; i < (int)vc.size(); i++) {
        if (!u[i]) continue;
        move_inside(vc[i]);
        if (press_button() > 1) {
            move_outside(vc[i]);
        }
        else {
            toremove.push_back(vc[i]);
            cnt++;
        }
    }
    for (int i = 0; i < (int)vc.size(); i++) {
        if (u[i]) continue;
        move_inside(vc[i]);
        if (press_button() > 1) u[i] = true;
        move_outside(vc[i]);
    }
    for (int i:toremove) move_outside(i);
    vector<int> nxt;
    for (int i = 0; i < (int)vc.size(); i++) {
        if (!u[i]) nxt.push_back(vc[i]);
    }
    return make_pair(nxt, cnt);
}
int get_min(vector<int> vc, int spec)
{
    if (spec == 1) return vc.size();
    int mx = vc.size() / spec;
    auto [v, k] = check(vc, mx);
    if (v.size() == vc.size()) return mx;
    else return get_min(v, spec - k);
}
int min_cardinality(int N) {
    vector<int> vc;
    for (int i = 0; i < N; i++) vc.push_back(i);
    int cnt = 0;
    vector<int> toremove;
    for (int i = 0; i < N; i++) {
        move_inside(i);
        if (press_button() >= 2) {
            move_outside(i);
        }
        else {
            toremove.push_back(i);
            cnt++;
        }
    }
    for (int i:toremove) move_outside(i);
    return get_min(vc, cnt);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...