Submission #706298

#TimeUsernameProblemLanguageResultExecution timeMemory
706298danikoynovRarest Insects (IOI22_insects)C++17
10 / 100
423 ms336 KiB
#include "insects.h"
#include<bits/stdc++.h>

using namespace std;
const int maxn = 2010;

int par[maxn], rnk[maxn];
int find_leader(int v)
{
    return (v == par[v]) ? v : (par[v] = find_leader(par[v]));
}

void unite(int v, int u)
{
    v = find_leader(v);
    u = find_leader(u);
    if (v == u)
        return;

    if (rand() % 2)
        swap(v, u);
    par[u] = v;
    rnk[v] += rnk[u];
}

int used[maxn];
int min_cardinality(int N)
{
    vector < int > idc;
    for (int i = 0; i < N; i ++)
        idc.push_back(i);
    random_shuffle(idc.begin(), idc.end());

    move_inside(idc[0]);
    for (int i = 0; i < N; i ++)
    {
        par[i] = i;
        rnk[i] = 1;
    }
    used[0] = 1;
    for (int i = 1; i < N; i ++)
    {
        move_inside(idc[i]);
        int act = press_button();
        used[i] = 1;
        if (act == 1)
            continue;
        int j = 0;
        while(act == 2)
        {
            if (used[j]);
            {
                move_outside(idc[j]);

                act = press_button();
            }
            j ++;
        }
        j --;
        unite(i, j);
        while(j >= 0)
        {
            if (used[j])
                move_inside(idc[j]);
            j --;
        }
        move_outside(idc[i]);
        used[i] = 0;
    }

    int ans = N;
    for (int i = 0; i < N; i ++)
        ans = min(ans, rnk[find_leader(i)]);
    return ans;
}

Compilation message (stderr)

insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:51:13: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   51 |             if (used[j]);
      |             ^~
insects.cpp:52:13: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   52 |             {
      |             ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...