Submission #787866

#TimeUsernameProblemLanguageResultExecution timeMemory
787866AndreyRarest Insects (IOI22_insects)C++17
99.95 / 100
64 ms360 KiB
#include "insects.h"
#include<bits/stdc++.h>
using namespace std;

int n,p = 0,l,r,x = 1;
vector<bool> idk(10000,true);
vector<bool> no(10000,true);

void check(int a) {
    vector<bool> bruh(n,true);
    vector<int> wut(0);
    vector<int> yay(0);
    int br = x*p;
    for(int i = 0; i < n && br < p*a; i++) {
        if(idk[i] && no[i]) {
            move_inside(i);
            if(press_button() > a) {
                bruh[i] = false;
                yay.push_back(i);
                move_outside(i);
            }
            else {
                br++;
                wut.push_back(i);
            }
        }
    }
    if(br == p*a) {
        l = a;
        for(int i = 0; i < wut.size(); i++) {
            idk[wut[i]] = false;
        }
        x = a;
        return;
    }
    else {
        r = a-((p*a-br)/p)-1;
        l = max(l,br-(p-1)*a);
        if(l == r) {
            return;
        }
        for(int i = 0; i < n; i++) {
            if(bruh[i] && idk[i] && no[i]) {
                move_outside(i);
            }
        }
        for(int i = 0; i < yay.size(); i++) {
            no[yay[i]] = false;
        }
        return;
    }
}

int min_cardinality(int N) {
    n = N;
    int m;
    l = 1;
    vector<bool> bruh(n,true);
    vector<int> yay(0);
    for(int i = 0; i < n; i++) {
        move_inside(i);
        if(press_button() > 1) {
            move_outside(i);
            bruh[i] = false;
        }
        else {
            p++;
            yay.push_back(i);
        }
    }
    for(int i = 0; i < p; i++) {
        idk[yay[i]] = false;
    }
    r = n/p;
    if(p == 1) {
        return n;
    }
    while(l < r) {
        m = (l+r+1)/2;
       /* if(m < r && (rand()%2)) {
            m++;
        }*/
        check(m);
    }
    return l;
}

Compilation message (stderr)

insects.cpp: In function 'void check(int)':
insects.cpp:30:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |         for(int i = 0; i < wut.size(); i++) {
      |                        ~~^~~~~~~~~~~~
insects.cpp:47:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |         for(int i = 0; i < yay.size(); i++) {
      |                        ~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...