Submission #787918

# Submission time Handle Problem Language Result Execution time Memory
787918 2023-07-19T14:26:01 Z borisAngelov Rarest Insects (IOI22_insects) C++17
100 / 100
50 ms 420 KB
#include "insects.h"
#include <bits/stdc++.h>

using namespace std;

const int maxn = 2005;

int n;

vector<int> machine;
bool is_inside[maxn];

int machine_initial_size = 0;

vector<int> last_add;

bool skip[maxn];
vector<int> to_skip;

int shuffled_indexes[maxn];

bool check(int max_equal)
{
    for (int i = 0; i <= n - 1; ++i)
    {
        if (is_inside[i] == true || skip[i] == true)
        {
            continue;
        }

        move_inside(shuffled_indexes[i]);

        if (press_button() > max_equal)
        {
            to_skip.push_back(i);
            move_outside(shuffled_indexes[i]);
        }
        else
        {
            last_add.push_back(i);
            is_inside[i] = true;
        }

        int curr_size = last_add.size() + machine.size();

        if (curr_size == max_equal * machine_initial_size)
        {
            return true;
        }
    }

    return false;
}

int min_cardinality(int N)
{
    n = N;

    for (int i = 0; i <= n - 1; ++i)
    {
        shuffled_indexes[i] = i;
    }

    random_shuffle(shuffled_indexes, shuffled_indexes + n);

    for (int i = 0; i <= n - 1; ++i)
    {
        move_inside(shuffled_indexes[i]);

        int result = press_button();

        if (result > 1)
        {
            move_outside(shuffled_indexes[i]);
        }
        else
        {
            machine.push_back(i);
            is_inside[i] = true;
            ++machine_initial_size;
        }
    }

    if (machine_initial_size == 1)
    {
        return n;
    }

    int l = 1;
    int r = n / machine_initial_size + 1;

    vector<int> answers(n + 5, -1);

    while (l < r - 1)
    {
        int mid = (l + r) / 2;

        last_add.clear();
        to_skip.clear();

        int result = answers[mid];

        if (result == -1)
        {
            result = check(mid);
            answers[mid] = result;
        }

        if (result == true)
        {
            l = mid;

            for (int i = 0; i < last_add.size(); ++i)
            {
                machine.push_back(last_add[i]);
            }
        }
        else
        {
            r = mid;

            for (int i = 0; i < last_add.size(); ++i)
            {
                move_outside(shuffled_indexes[last_add[i]]);
                is_inside[last_add[i]] = false;
            }

            for (int i = 0; i < to_skip.size(); ++i)
            {
                skip[to_skip[i]] = true;
            }
        }
    }

    return l;
}

Compilation message

insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:113:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  113 |             for (int i = 0; i < last_add.size(); ++i)
      |                             ~~^~~~~~~~~~~~~~~~~
insects.cpp:122:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  122 |             for (int i = 0; i < last_add.size(); ++i)
      |                             ~~^~~~~~~~~~~~~~~~~
insects.cpp:128:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  128 |             for (int i = 0; i < to_skip.size(); ++i)
      |                             ~~^~~~~~~~~~~~~~~~
# 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 1 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 2 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 5 ms 208 KB Output is correct
9 Correct 5 ms 208 KB Output is correct
10 Correct 4 ms 208 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 4 ms 336 KB Output is correct
13 Correct 5 ms 308 KB Output is correct
14 Correct 5 ms 208 KB Output is correct
15 Correct 5 ms 208 KB Output is correct
16 Correct 4 ms 300 KB Output is correct
17 Correct 4 ms 208 KB Output is correct
18 Correct 4 ms 208 KB Output is correct
19 Correct 4 ms 312 KB Output is correct
20 Correct 5 ms 208 KB Output is correct
21 Correct 2 ms 208 KB Output is correct
22 Correct 2 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 1 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 2 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 5 ms 208 KB Output is correct
9 Correct 5 ms 208 KB Output is correct
10 Correct 4 ms 208 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 4 ms 336 KB Output is correct
13 Correct 5 ms 308 KB Output is correct
14 Correct 5 ms 208 KB Output is correct
15 Correct 5 ms 208 KB Output is correct
16 Correct 4 ms 300 KB Output is correct
17 Correct 4 ms 208 KB Output is correct
18 Correct 4 ms 208 KB Output is correct
19 Correct 4 ms 312 KB Output is correct
20 Correct 5 ms 208 KB Output is correct
21 Correct 2 ms 208 KB Output is correct
22 Correct 2 ms 208 KB Output is correct
23 Correct 11 ms 208 KB Output is correct
24 Correct 7 ms 316 KB Output is correct
25 Correct 23 ms 208 KB Output is correct
26 Correct 24 ms 312 KB Output is correct
27 Correct 23 ms 312 KB Output is correct
28 Correct 10 ms 208 KB Output is correct
29 Correct 15 ms 296 KB Output is correct
30 Correct 16 ms 208 KB Output is correct
31 Correct 19 ms 304 KB Output is correct
32 Correct 16 ms 300 KB Output is correct
33 Correct 9 ms 312 KB Output is correct
34 Correct 22 ms 300 KB Output is correct
35 Correct 22 ms 208 KB Output is correct
36 Correct 21 ms 304 KB Output is correct
37 Correct 17 ms 296 KB Output is correct
38 Correct 21 ms 208 KB Output is correct
39 Correct 16 ms 296 KB Output is correct
40 Correct 12 ms 312 KB Output is correct
41 Correct 7 ms 312 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 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 13 ms 208 KB Output is correct
8 Correct 14 ms 304 KB Output is correct
9 Correct 42 ms 292 KB Output is correct
10 Correct 44 ms 288 KB Output is correct
11 Correct 45 ms 308 KB Output is correct
12 Correct 17 ms 316 KB Output is correct
13 Correct 45 ms 208 KB Output is correct
14 Correct 41 ms 308 KB Output is correct
15 Correct 19 ms 316 KB Output is correct
16 Correct 37 ms 288 KB Output is correct
17 Correct 32 ms 304 KB Output is correct
18 Correct 33 ms 208 KB Output is correct
19 Correct 27 ms 300 KB Output is correct
20 Correct 36 ms 308 KB Output is correct
21 Correct 35 ms 304 KB Output is correct
22 Correct 50 ms 288 KB Output is correct
23 Correct 26 ms 308 KB Output is correct
24 Correct 38 ms 308 KB Output is correct
25 Correct 18 ms 316 KB Output is correct
26 Correct 17 ms 316 KB Output is correct
27 Correct 40 ms 296 KB Output is correct
28 Correct 34 ms 316 KB Output is correct
29 Correct 29 ms 312 KB Output is correct
30 Correct 34 ms 308 KB Output is correct
31 Correct 47 ms 304 KB Output is correct
32 Correct 39 ms 296 KB Output is correct
33 Correct 44 ms 292 KB Output is correct
34 Correct 37 ms 292 KB Output is correct
35 Correct 17 ms 208 KB Output is correct
36 Correct 24 ms 316 KB Output is correct
37 Correct 34 ms 304 KB Output is correct
38 Correct 21 ms 312 KB Output is correct
39 Correct 24 ms 308 KB Output is correct
40 Correct 40 ms 300 KB Output is correct
41 Correct 45 ms 308 KB Output is correct
42 Correct 42 ms 300 KB Output is correct
43 Correct 12 ms 208 KB Output is correct
44 Correct 28 ms 420 KB Output is correct
45 Correct 28 ms 296 KB Output is correct
46 Correct 31 ms 312 KB Output is correct
47 Correct 20 ms 336 KB Output is correct
48 Correct 28 ms 308 KB Output is correct