Submission #708734

#TimeUsernameProblemLanguageResultExecution timeMemory
708734t6twotwoRarest Insects (IOI22_insects)C++17
0 / 100
213 ms336 KiB
#include "insects.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int min_cardinality(int n) {
    vector<bool> in(n);
    for (int i = 0; i < n; i++) {
        move_inside(i);
        if (press_button() == 2) move_outside(i);
        else in[i] = 1;
    }
    int type = 0;
    for (int i = 0; i < n; i++) {
        if (in[i]) {
            type++;
            in[i] = 0;
            move_outside(i);
        }
    }
    int lo = 1, hi = n / type;
    while (lo < hi) {
        int x = (lo + hi + 1) / 2;
        for (int i = 0; i < n; i++) {
            move_inside(i);
            if (press_button() == x + 1) move_outside(i);
            else in[i] = 1;
        }
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            if (in[i]) {
                cnt++;
                in[i] = 0;
                move_outside(i);
            }
        }
        if (cnt == x * type) lo = x;
        else hi = x - 1, n = hi * type;
    }
    return lo;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...