Submission #627555

# Submission time Handle Problem Language Result Execution time Memory
627555 2022-08-12T16:50:58 Z I_love_Hoang_Yen Rarest Insects (IOI22_insects) C++17
83.67 / 100
103 ms 472 KB
#include "insects.h"
#include "bits/stdc++.h"
#define SZ(s) ((int) s.size())
using namespace std;

#ifndef RR
#define DEBUG(X)
#endif

/* sub1
// Sub 1 {{{
int min_cardinality(int n) {
    std::vector<int> v_ids(n);
    std::iota(v_ids.begin(), v_ids.end(), 0);

    std::set<int> ids(v_ids.begin(), v_ids.end());
    int freq = 0, last_cnt = 0;

    while (true) {
        ++freq;
        std::set<int> new_ids;

        for (int id : ids) {
            move_inside(id);
            if (press_button() > freq) {
                move_outside(id);
                new_ids.insert(id);
            }
        }

        int unique_values = SZ(ids) - SZ(new_ids);
        if (unique_values < last_cnt) {
            return freq - 1;
        }
        last_cnt = unique_values;

        if (unique_values > SZ(new_ids)) {
            return freq;
        }

        ids = std::move(new_ids);
    }

    return 0;
}
// }}}
*/

mt19937_64 rng(58);

int min_cardinality(int n) {
    std::set<int> insides;
    int freq = 1;
    std::vector<int> order(n);
    std::iota(order.begin(), order.end(), 0);
    std::shuffle(order.begin(), order.end(), rng);

    auto add = [&] (int i) {
        insides.insert(i);
        move_inside(order[i]);
    };
    auto remove = [&] (int i) {
        insides.erase(i);
        move_outside(order[i]);
    };

    for (int i = 0; i < n; ++i) {
        add(i);
        if (press_button() > 1) {
            remove(i);
        }
    }
    int unique_vals = SZ(insides);
    DEBUG(unique_vals);

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

        assert(mid != freq);
        if (mid > freq) {
            for (int i = 0; i < n; ++i) {
                if (!insides.count(i)) {
                    add(i);
                    if (press_button() > mid) {
                        remove(i);
                    }
                }
            }
        } else {
            auto ids = insides;
            for (int id : ids) remove(id);

            for (int i : ids) {
                add(i);
                if (press_button() > mid) {
                    remove(i);
                }
            }
        }
        freq = mid;
        int total = SZ(insides);

        if (total >= unique_vals * mid) {
            // all values have at least frequency = mid
            res = mid;
            l = mid + 1;
        } else {
            r = mid - 1;
        }
    }
    return res;
}
# 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 304 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 3 ms 208 KB Output is correct
9 Correct 5 ms 208 KB Output is correct
10 Correct 5 ms 208 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 6 ms 208 KB Output is correct
13 Correct 5 ms 308 KB Output is correct
14 Correct 6 ms 208 KB Output is correct
15 Correct 6 ms 208 KB Output is correct
16 Correct 8 ms 340 KB Output is correct
17 Correct 7 ms 208 KB Output is correct
18 Correct 5 ms 208 KB Output is correct
19 Correct 7 ms 208 KB Output is correct
20 Correct 4 ms 304 KB Output is correct
21 Correct 3 ms 304 KB Output is correct
22 Correct 2 ms 304 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 304 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 3 ms 208 KB Output is correct
9 Correct 5 ms 208 KB Output is correct
10 Correct 5 ms 208 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 6 ms 208 KB Output is correct
13 Correct 5 ms 308 KB Output is correct
14 Correct 6 ms 208 KB Output is correct
15 Correct 6 ms 208 KB Output is correct
16 Correct 8 ms 340 KB Output is correct
17 Correct 7 ms 208 KB Output is correct
18 Correct 5 ms 208 KB Output is correct
19 Correct 7 ms 208 KB Output is correct
20 Correct 4 ms 304 KB Output is correct
21 Correct 3 ms 304 KB Output is correct
22 Correct 2 ms 304 KB Output is correct
23 Correct 22 ms 304 KB Output is correct
24 Correct 9 ms 336 KB Output is correct
25 Correct 24 ms 312 KB Output is correct
26 Correct 40 ms 328 KB Output is correct
27 Correct 29 ms 288 KB Output is correct
28 Correct 8 ms 208 KB Output is correct
29 Correct 27 ms 304 KB Output is correct
30 Correct 25 ms 296 KB Output is correct
31 Correct 51 ms 328 KB Output is correct
32 Correct 51 ms 320 KB Output is correct
33 Correct 59 ms 300 KB Output is correct
34 Correct 38 ms 300 KB Output is correct
35 Correct 38 ms 304 KB Output is correct
36 Correct 40 ms 304 KB Output is correct
37 Correct 38 ms 420 KB Output is correct
38 Correct 13 ms 336 KB Output is correct
39 Correct 20 ms 352 KB Output is correct
40 Correct 12 ms 324 KB Output is correct
41 Correct 8 ms 280 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 248 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 41 ms 448 KB Output is correct
8 Correct 19 ms 352 KB Output is correct
9 Correct 48 ms 300 KB Output is correct
10 Partially correct 73 ms 304 KB Output is partially correct
11 Correct 50 ms 304 KB Output is correct
12 Correct 14 ms 340 KB Output is correct
13 Correct 45 ms 304 KB Output is correct
14 Partially correct 57 ms 304 KB Output is partially correct
15 Partially correct 99 ms 472 KB Output is partially correct
16 Partially correct 97 ms 432 KB Output is partially correct
17 Partially correct 101 ms 468 KB Output is partially correct
18 Partially correct 79 ms 352 KB Output is partially correct
19 Partially correct 75 ms 416 KB Output is partially correct
20 Partially correct 103 ms 460 KB Output is partially correct
21 Partially correct 95 ms 440 KB Output is partially correct
22 Partially correct 66 ms 296 KB Output is partially correct
23 Partially correct 54 ms 308 KB Output is partially correct
24 Correct 52 ms 324 KB Output is correct
25 Correct 24 ms 348 KB Output is correct
26 Correct 15 ms 344 KB Output is correct
27 Correct 50 ms 308 KB Output is correct
28 Correct 49 ms 312 KB Output is correct
29 Correct 59 ms 304 KB Output is correct
30 Correct 45 ms 304 KB Output is correct
31 Partially correct 78 ms 308 KB Output is partially correct
32 Partially correct 65 ms 344 KB Output is partially correct
33 Partially correct 37 ms 348 KB Output is partially correct
34 Partially correct 66 ms 292 KB Output is partially correct
35 Correct 44 ms 360 KB Output is correct
36 Correct 53 ms 432 KB Output is correct
37 Partially correct 82 ms 436 KB Output is partially correct
38 Partially correct 89 ms 420 KB Output is partially correct
39 Correct 55 ms 296 KB Output is correct
40 Correct 51 ms 308 KB Output is correct
41 Correct 38 ms 336 KB Output is correct
42 Correct 99 ms 380 KB Output is correct
43 Correct 11 ms 308 KB Output is correct
44 Correct 60 ms 300 KB Output is correct
45 Correct 37 ms 292 KB Output is correct
46 Correct 24 ms 332 KB Output is correct
47 Correct 26 ms 328 KB Output is correct
48 Correct 22 ms 332 KB Output is correct