Submission #825880

#TimeUsernameProblemLanguageResultExecution timeMemory
825880PixelCatRarest Insects (IOI22_insects)C++17
47.50 / 100
209 ms520 KiB
#include "insects.h"

#ifdef NYAOWO
#include "stub.cpp"
#endif

#include <bits/stdc++.h>
#define For(i, a, b) for(int i = a; i <= b; i++)
#define Forr(i, a, b) for(int i = a; i >= b; i--)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
#define eb emplace_back
// #define int LL
using namespace std;
using i32 = int32_t;
using LL = long long;
using pii = pair<int, int>;

int find_types(int n) {
    vector<int> rep;
    For(i, 0, n - 1) {
        move_inside(i);
        if(press_button() == 1) {
            rep.eb(i);
        } else {
            move_outside(i);
        }
    }
    for(auto &i:rep) move_outside(i);
    return sz(rep);
}

// # of all types >= k ?
bool check(int k, int n, int m) {
    vector<int> owo;
    For(i, 0, n - 1) {
        move_inside(i);
        // cerr << press_button() << " \n"[i == n - 1];
        if(press_button() <= k) {
            owo.eb(i);
        } else {
            move_outside(i);
        }
    }
    for(auto &i:owo) move_outside(i);
    // cerr << k << " " << sz(owo) << "\n";
    return m * k == sz(owo);
}

int min_cardinality(int n) {
    int m = find_types(n);
    cerr << m << "\n";
    int hi = n + 1, lo = 0;
    while(hi - lo > 1) {
        int mi = (hi + lo) / 2;
        if(check(mi, n, m)) lo = mi;
        else hi = mi;
    }
    return lo;
}

/*

6
5 8 9 5 9 9

1
7

*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...