Submission #628862

# Submission time Handle Problem Language Result Execution time Memory
628862 2022-08-13T18:40:39 Z phathnv Rarest Insects (IOI22_insects) C++17
100 / 100
96 ms 428 KB
#include "insects.h"
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 2000;

bool isIn[MAX_N], nxt[MAX_N];

int ask(const vector<int> &a) {
    for (int i = 0; i < MAX_N; ++i) {
        nxt[i] = 0;
    }
    for (auto x : a) {
        nxt[x] = 1;
    }
    for (int i = 0; i < MAX_N; ++i) {
        if (isIn[i] > nxt[i]) {
            move_outside(i);
        }
        if (isIn[i] < nxt[i]) {
            move_inside(i);
        }
        isIn[i] = nxt[i];
    }
    return press_button();
}

int min_cardinality(int n) {
    vector<int> a(n);
    iota(a.begin(), a.end(), 0);
    srand(123);
    random_shuffle(a.begin(), a.end());

    vector<int> nxt, inside;
    for (auto x : a) {
        inside.push_back(x);
        if (ask(inside) > 1) {
            inside.pop_back();
            nxt.push_back(x);
        }
    }
    int numDistinct = inside.size();
    int res = 1;
    a = nxt;

    int l = 1, r = (int) a.size() / numDistinct;
    while (l <= r) {
        int mid = (l + r) >> 1;

        vector<int> outside;
        inside.clear();
        for (auto x : a) {
            if ((int)inside.size() == mid * numDistinct) {
                outside.push_back(x);
                continue;
            }

            inside.push_back(x);
            if ((int)inside.size() <= mid) {
                continue;
            }
            if (ask(inside) > mid) {
                inside.pop_back();
                outside.push_back(x);
            }
        }
        if ((int)inside.size() == numDistinct * mid) {
            res += mid;
            a = outside;
            l = 1;
            r = (int)a.size() / numDistinct;
        } else {
            a = inside;
            l = max(1, (int)a.size() - mid * (numDistinct - 1));
            r = (int)a.size() / numDistinct;
        }
    }

    return res;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 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 4 ms 304 KB Output is correct
7 Correct 3 ms 208 KB Output is correct
8 Correct 7 ms 208 KB Output is correct
9 Correct 8 ms 208 KB Output is correct
10 Correct 5 ms 208 KB Output is correct
11 Correct 4 ms 208 KB Output is correct
12 Correct 7 ms 208 KB Output is correct
13 Correct 7 ms 208 KB Output is correct
14 Correct 6 ms 208 KB Output is correct
15 Correct 6 ms 208 KB Output is correct
16 Correct 6 ms 280 KB Output is correct
17 Correct 7 ms 208 KB Output is correct
18 Correct 6 ms 208 KB Output is correct
19 Correct 5 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 1 ms 208 KB Output is correct
2 Correct 1 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 4 ms 304 KB Output is correct
7 Correct 3 ms 208 KB Output is correct
8 Correct 7 ms 208 KB Output is correct
9 Correct 8 ms 208 KB Output is correct
10 Correct 5 ms 208 KB Output is correct
11 Correct 4 ms 208 KB Output is correct
12 Correct 7 ms 208 KB Output is correct
13 Correct 7 ms 208 KB Output is correct
14 Correct 6 ms 208 KB Output is correct
15 Correct 6 ms 208 KB Output is correct
16 Correct 6 ms 280 KB Output is correct
17 Correct 7 ms 208 KB Output is correct
18 Correct 6 ms 208 KB Output is correct
19 Correct 5 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 12 ms 312 KB Output is correct
24 Correct 14 ms 208 KB Output is correct
25 Correct 22 ms 304 KB Output is correct
26 Correct 23 ms 312 KB Output is correct
27 Correct 24 ms 312 KB Output is correct
28 Correct 12 ms 308 KB Output is correct
29 Correct 30 ms 312 KB Output is correct
30 Correct 39 ms 308 KB Output is correct
31 Correct 27 ms 308 KB Output is correct
32 Correct 15 ms 208 KB Output is correct
33 Correct 27 ms 208 KB Output is correct
34 Correct 28 ms 308 KB Output is correct
35 Correct 27 ms 308 KB Output is correct
36 Correct 16 ms 208 KB Output is correct
37 Correct 34 ms 208 KB Output is correct
38 Correct 22 ms 308 KB Output is correct
39 Correct 26 ms 300 KB Output is correct
40 Correct 19 ms 316 KB Output is correct
41 Correct 14 ms 296 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 1 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 28 ms 312 KB Output is correct
8 Correct 30 ms 312 KB Output is correct
9 Correct 63 ms 312 KB Output is correct
10 Correct 64 ms 316 KB Output is correct
11 Correct 58 ms 308 KB Output is correct
12 Correct 48 ms 308 KB Output is correct
13 Correct 73 ms 308 KB Output is correct
14 Correct 67 ms 308 KB Output is correct
15 Correct 45 ms 292 KB Output is correct
16 Correct 57 ms 312 KB Output is correct
17 Correct 96 ms 312 KB Output is correct
18 Correct 50 ms 316 KB Output is correct
19 Correct 45 ms 316 KB Output is correct
20 Correct 38 ms 320 KB Output is correct
21 Correct 70 ms 308 KB Output is correct
22 Correct 40 ms 320 KB Output is correct
23 Correct 54 ms 308 KB Output is correct
24 Correct 56 ms 316 KB Output is correct
25 Correct 35 ms 308 KB Output is correct
26 Correct 31 ms 316 KB Output is correct
27 Correct 43 ms 308 KB Output is correct
28 Correct 45 ms 308 KB Output is correct
29 Correct 41 ms 308 KB Output is correct
30 Correct 68 ms 320 KB Output is correct
31 Correct 81 ms 312 KB Output is correct
32 Correct 71 ms 328 KB Output is correct
33 Correct 78 ms 316 KB Output is correct
34 Correct 66 ms 312 KB Output is correct
35 Correct 39 ms 312 KB Output is correct
36 Correct 69 ms 316 KB Output is correct
37 Correct 72 ms 320 KB Output is correct
38 Correct 62 ms 336 KB Output is correct
39 Correct 52 ms 320 KB Output is correct
40 Correct 53 ms 312 KB Output is correct
41 Correct 64 ms 304 KB Output is correct
42 Correct 60 ms 308 KB Output is correct
43 Correct 12 ms 312 KB Output is correct
44 Correct 51 ms 428 KB Output is correct
45 Correct 37 ms 316 KB Output is correct
46 Correct 41 ms 312 KB Output is correct
47 Correct 36 ms 308 KB Output is correct
48 Correct 40 ms 312 KB Output is correct