Submission #757709

# Submission time Handle Problem Language Result Execution time Memory
757709 2023-06-13T15:25:58 Z boris_mihov Rarest Insects (IOI22_insects) C++17
100 / 100
70 ms 428 KB
#include "insects.h"
#include <algorithm>
#include <iostream>
#include <numeric>
#include <random>
#include <cassert>
#include <vector>

typedef long long llong;
const int MAXN = 2000 + 10;
const int INF  = 1e9;

int n, d;
int perm[MAXN];
bool isInside[MAXN];
std::vector <int> inside;
std::vector <int> toRemove;
std::vector <int> lastlyAdded;

void moveInside(int idx)
{
    assert(!isInside[idx]);
    move_inside(perm[idx]);
}

void moveOutside(int idx)
{
    move_outside(perm[idx]);
}

bool check(int to)
{
    for (int i = 1 ; i <= n ; ++i)
    {
        if (isInside[i])
        {
            continue;
        }

        moveInside(i);
        int res = press_button();
        if (res > to)
        {
            moveOutside(i);
            toRemove.push_back(i);
        } else
        {
            lastlyAdded.push_back(i);
            isInside[i] = true;
        }

        if (lastlyAdded.size() + inside.size() == to * d)
        {
            return true;
        }
    }

    return false;
}

std::mt19937 mt(69);
int min_cardinality(int N) 
{
    n = N;
    std::iota(perm + 1, perm + 1 + n, 0);
    std::shuffle(perm + 1, perm + 1 + n, mt);
    for (int i = 1 ; i <= n ; ++i)
    {
        moveInside(i);
        if (press_button() > 1)
        {
            moveOutside(i);
        } else
        {
            inside.push_back(i);
            isInside[i] = true;
        }
    }

    d = inside.size();
    int l = 1, r = n / d + 1, mid;
    while (l < r - 1)
    {
        mid = (l + r) / 2;
        lastlyAdded.clear();
        toRemove.clear();
        if (check(mid))
        {
            l = mid;
            for (const int &i : lastlyAdded)
            {
                inside.push_back(i);
            }
        } else
        {
            r = mid;
            for (const int &i : lastlyAdded)
            {
                moveOutside(i);
                isInside[i] = false;
            }

            for (const int &i : toRemove)
            {
                isInside[i] = true;
            }
        }
    }

    return l;
}

Compilation message

insects.cpp: In function 'bool check(int)':
insects.cpp:52:48: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   52 |         if (lastlyAdded.size() + inside.size() == to * d)
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 3 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 2 ms 316 KB Output is correct
9 Correct 5 ms 304 KB Output is correct
10 Correct 5 ms 312 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 7 ms 208 KB Output is correct
13 Correct 3 ms 208 KB Output is correct
14 Correct 3 ms 208 KB Output is correct
15 Correct 5 ms 304 KB Output is correct
16 Correct 6 ms 208 KB Output is correct
17 Correct 7 ms 308 KB Output is correct
18 Correct 6 ms 208 KB Output is correct
19 Correct 4 ms 208 KB Output is correct
20 Correct 4 ms 208 KB Output is correct
21 Correct 4 ms 208 KB Output is correct
22 Correct 3 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 3 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 2 ms 316 KB Output is correct
9 Correct 5 ms 304 KB Output is correct
10 Correct 5 ms 312 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 7 ms 208 KB Output is correct
13 Correct 3 ms 208 KB Output is correct
14 Correct 3 ms 208 KB Output is correct
15 Correct 5 ms 304 KB Output is correct
16 Correct 6 ms 208 KB Output is correct
17 Correct 7 ms 308 KB Output is correct
18 Correct 6 ms 208 KB Output is correct
19 Correct 4 ms 208 KB Output is correct
20 Correct 4 ms 208 KB Output is correct
21 Correct 4 ms 208 KB Output is correct
22 Correct 3 ms 208 KB Output is correct
23 Correct 13 ms 208 KB Output is correct
24 Correct 9 ms 208 KB Output is correct
25 Correct 23 ms 208 KB Output is correct
26 Correct 21 ms 208 KB Output is correct
27 Correct 22 ms 208 KB Output is correct
28 Correct 8 ms 208 KB Output is correct
29 Correct 30 ms 300 KB Output is correct
30 Correct 19 ms 312 KB Output is correct
31 Correct 20 ms 300 KB Output is correct
32 Correct 25 ms 296 KB Output is correct
33 Correct 16 ms 208 KB Output is correct
34 Correct 20 ms 208 KB Output is correct
35 Correct 29 ms 308 KB Output is correct
36 Correct 29 ms 208 KB Output is correct
37 Correct 20 ms 208 KB Output is correct
38 Correct 22 ms 208 KB Output is correct
39 Correct 10 ms 316 KB Output is correct
40 Correct 15 ms 208 KB Output is correct
41 Correct 11 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 50 ms 320 KB Output is correct
8 Correct 16 ms 316 KB Output is correct
9 Correct 70 ms 296 KB Output is correct
10 Correct 49 ms 312 KB Output is correct
11 Correct 40 ms 304 KB Output is correct
12 Correct 28 ms 208 KB Output is correct
13 Correct 44 ms 304 KB Output is correct
14 Correct 54 ms 304 KB Output is correct
15 Correct 20 ms 336 KB Output is correct
16 Correct 53 ms 296 KB Output is correct
17 Correct 36 ms 308 KB Output is correct
18 Correct 40 ms 320 KB Output is correct
19 Correct 23 ms 296 KB Output is correct
20 Correct 31 ms 324 KB Output is correct
21 Correct 55 ms 304 KB Output is correct
22 Correct 34 ms 420 KB Output is correct
23 Correct 44 ms 308 KB Output is correct
24 Correct 54 ms 428 KB Output is correct
25 Correct 23 ms 208 KB Output is correct
26 Correct 19 ms 208 KB Output is correct
27 Correct 53 ms 304 KB Output is correct
28 Correct 50 ms 292 KB Output is correct
29 Correct 26 ms 208 KB Output is correct
30 Correct 31 ms 312 KB Output is correct
31 Correct 64 ms 308 KB Output is correct
32 Correct 35 ms 304 KB Output is correct
33 Correct 50 ms 208 KB Output is correct
34 Correct 42 ms 304 KB Output is correct
35 Correct 40 ms 312 KB Output is correct
36 Correct 35 ms 344 KB Output is correct
37 Correct 43 ms 304 KB Output is correct
38 Correct 52 ms 208 KB Output is correct
39 Correct 35 ms 296 KB Output is correct
40 Correct 39 ms 304 KB Output is correct
41 Correct 38 ms 312 KB Output is correct
42 Correct 42 ms 208 KB Output is correct
43 Correct 10 ms 208 KB Output is correct
44 Correct 31 ms 304 KB Output is correct
45 Correct 33 ms 328 KB Output is correct
46 Correct 31 ms 300 KB Output is correct
47 Correct 30 ms 328 KB Output is correct
48 Correct 25 ms 300 KB Output is correct