Submission #977605

#TimeUsernameProblemLanguageResultExecution timeMemory
977605Vedang1006드문 곤충 (IOI22_insects)C++17
47.52 / 100
128 ms1088 KiB
#include <bits/stdc++.h>
#include "insects.h"

using namespace std;

bool used[2000];
bool used2[2000];

void tryFillUsed2(int N, int target)
{
    for (int i = 0; i < N; i++)
    {
        if (!used[i])
        {
            move_inside(i);
            if (press_button() > target) move_outside(i);
            else
            {
                used2[i] = true;
            }
        }
    }
}

int min_cardinality(int N)
{
    int numberOfDistinctTypes = 0;

    for (int i = 0; i < N; i++)
    {
        move_inside(i);
        if (press_button() != 1) move_outside(i);
        else
        {
            numberOfDistinctTypes += 1;
            used[i] = true;
        }
    }

    int i = 1;

    for (int j = 1024; j > 0; j /= 2)
    {
        if (i + j <= 2000)
        {
            tryFillUsed2(N, i + j);
            int totalSumUsed2 = 0;
            for (int i = 0; i < N; i++) totalSumUsed2 += used[i] + used2[i];

            if (numberOfDistinctTypes * (i + j) != totalSumUsed2)
            {
                for (int idx = 0; idx < N; idx++)
                {
                    if (used2[idx]) move_outside(idx);
                    used2[idx] = false;
                }
            }
            else
            {
                for (int idx = 0; idx < N; idx++)
                {
                    used[idx] |= used2[idx];
                    used2[idx] = false;
                }

                i += j;
            }
        }
    }

    return i;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...