Submission #797529

#TimeUsernameProblemLanguageResultExecution timeMemory
797529TahirAliyevRarest Insects (IOI22_insects)C++17
53.16 / 100
121 ms416 KiB
#include "insects.h"
#include <bits/stdc++.h>

using namespace std;
//press_button
//move_outside
//move_inside

bool Inside[2001];

int min_cardinality(int N) {
    move_inside(0);
    Inside[0] = 1;
    
    int k = 1;
    for (int i = 1; i < N; i++)
    {
        move_inside(i);
        if(press_button() == 2){
            move_outside(i);
        }
        else{
            Inside[i] = 1;
            k++;
        }
    }
    int l = 2, r = N / k;
    int ans = 1;
    int t = k;
    while(l <= r){
        int mid = (l + r) / 2;
        vector<int> added;
        for (int i = 0; i < N; i++)
        {
            if(Inside[i]){
                continue;
            }
            move_inside(i);
            if(press_button() == mid + 1){
                move_outside(i);
            }
            else{
                Inside[i] = 1;
                t++;
                added.push_back(i);
            }
        }
        if(t == mid * k){
            l = mid + 1;
            ans = mid;
        }
        else{
            r = mid - 1;
            for(int i : added){
                move_outside(i);
                Inside[i] = 0;
                t--;
            }
        }
    }
    return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...