Submission #787677

#TimeUsernameProblemLanguageResultExecution timeMemory
787677AndreyRarest Insects (IOI22_insects)C++17
50 / 100
196 ms404 KiB
#include "insects.h"
#include<bits/stdc++.h>
using namespace std;

int n,p = 0;

bool check(int a) {
    vector<bool> bruh(n,true);
    int br = n;
    for(int i = 0; i < n; i++) {
        move_inside(i);
        if(press_button() > a) {
             bruh[i] = false;
             move_outside(i);
             br--;
        }
    }
    for(int i = 0; i < n; i++) {
        if(bruh[i]) {
            move_outside(i);
        }
    }
    if(br == p*a) {
        return false;
    }
    else {
        return true;
    }
}

int min_cardinality(int N) {
    n = N;
    int l = 1,r = n/2+1,m;
    vector<bool> bruh(n,true);
    for(int i = 0; i < n; i++) {
        move_inside(i);
        if(press_button() > 1) {
            move_outside(i);
            bruh[i] = false;
        }
        else {
            p++;
        }
    }
    for(int i = 0; i < n; i++) {
        if(bruh[i]) {
            move_outside(i);
        }
    }
    while(l < r) {
        m = (l+r+1)/2;
        if(check(m)) {
            r = m-1;
        }
        else {
            l = m;
        }
    }
    if(l > n/2) {
        return n;
    }
    return l;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...