Submission #1235614

#TimeUsernameProblemLanguageResultExecution timeMemory
1235614Muhammad_AneeqRarest Insects (IOI22_insects)C++17
92.99 / 100
22 ms416 KiB
#include "insects.h"
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <iostream>
using namespace std;
int const sz=2010;
bitset<sz>ind,ind1;
int ask()
{
    return press_button();
}
int min_cardinality(int N) 
{
    int colors=0;
    for (int i=0;i<N;i++)
    {
        ind[i]=1;
        move_inside(i);
        colors++;
        if (ask()>1)
        {
            ind[i]=0;
            move_outside(i);
            colors--;
        }
    }
    for (int i=0;i<N;i++)
        ind1[i]=1-ind[i];
    int cnt=colors;
    int st=1,en=N/colors+1;
    while (st+1<en)
    {
        int mid=(st+en)/2;
        for (int i=0;i<N;i++)
        {
            if (cnt==colors*mid)
                break;
            if (ind1[i])
            {
                ind[i]=1;
                cnt++;
                move_inside(i);
                if (ask()>mid)
                {
                    move_outside(i);
                    cnt--;
                    ind[i]=0;
                }
            }
        }
        if (cnt==colors*mid)
        {
            st=mid;
            if (st+1>=en)
                break;
            for (int i=0;i<N;i++)
            {
                if (ind[i])
                    ind1[i]=0;
            }
        }
        else
        {
            en=mid;
            if (st+1>=en)
                break;
            cnt=0;
            for (int i=0;i<N;i++)
            {
                if (ind[i])
                {
                    move_outside(i);
                    ind[i]=0;
                    ind1[i]=1;
                }
                else
                    ind1[i]=0;
            }
        }
    }
    return st;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...