Submission #859216

#TimeUsernameProblemLanguageResultExecution timeMemory
859216thinknoexitRarest Insects (IOI22_insects)C++17
53.16 / 100
93 ms856 KiB
#include <bits/stdc++.h>
#include "insects.h"
using namespace std;
using ll = long long;
int in[2020];
int min_cardinality(int n) {
    int type = 0;
    for (int i = 0;i < n;i++) {
        move_inside(i);
        if (press_button() == 2) {
            move_outside(i);
        }
        else in[i] = 1, type++;
    }
    if (type == 1) return n;
    if (type == n) return 1;
    if (type > n / 2) return 1;
    int mxans = n / type;
    int l = 1, r = mxans;
    while (l < r) {
        int mid = (l + r + 1) / 2;
        int sz = mid - l;
        int cnt = 0;
        for (int i = 0;i < n;i++) {
            if (in[i]) continue;
            move_inside(i);
            if (press_button() > mid) {
                move_outside(i);
            }
            else in[i] = mid, cnt++;
        }
        if (cnt < type * sz) {
            r = mid - 1;
            for (int i = 0;i < n;i++) if (in[i] == mid) move_outside(i), in[i] = 0;
        }
        else l = mid;
    }
    return l;
    // n , n , n
    /*
        ans <= n / type
        ans <= n - mx
    */
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...