Submission #706295

#TimeUsernameProblemLanguageResultExecution timeMemory
706295danikoynovRarest Insects (IOI22_insects)C++17
10 / 100
410 ms316 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)
{
    move_inside(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(i);
        int act = press_button();
        used[i] = 1;
        if (act == 1)
            continue;
        int j = 0;
        while(act == 2)
        {
            if (used[j]);
            {
                move_outside(j);

                act = press_button();
            }
            j ++;
        }
        j --;
        unite(i, j);
        while(j >= 0)
        {
            if (used[j])
                move_inside(j);
            j --;
        }
        move_outside(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:46:13: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   46 |             if (used[j]);
      |             ^~
insects.cpp:47:13: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   47 |             {
      |             ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...