Submission #627569

# Submission time Handle Problem Language Result Execution time Memory
627569 2022-08-12T16:59:45 Z I_love_Hoang_Yen Rarest Insects (IOI22_insects) C++17
83.67 / 100
116 ms 540 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;
}
// }}}
*/

int solve_small(int n, const std::set<int>& seeds) {
    std::set<int> used;
    int res = n;
    DEBUG(seeds);

    int n_unique = SZ(seeds);
    for (int turn = 0; turn + 1 < n_unique; ++turn) {
        std::set<int> cur;

        for (int i = 0; i < n; ++i) {
            if (!seeds.count(i) && !used.count(i)) {
                cur.insert(i);
                move_inside(i);

                if (press_button() != SZ(cur) + 1) {
                    move_outside(i);
                    cur.erase(i);
                }
            }
        }
        DEBUG(cur);

        used.insert(cur.begin(), cur.end());
        res = std::min(res, SZ(cur) + 1);
    }

    int remaining = n - SZ(used) - SZ(seeds) + 1;
    DEBUG(remaining);
    res = std::min(res, remaining);

    return res;
}

int min_cardinality(int n) {
    std::set<int> insides;
    int freq = 1;

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

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

    if (unique_vals == 2) {
        return solve_small(n, insides);
    }

    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 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 6 ms 208 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 4 ms 208 KB Output is correct
9 Correct 5 ms 296 KB Output is correct
10 Correct 7 ms 208 KB Output is correct
11 Correct 3 ms 208 KB Output is correct
12 Correct 6 ms 208 KB Output is correct
13 Correct 7 ms 208 KB Output is correct
14 Correct 4 ms 300 KB Output is correct
15 Correct 8 ms 208 KB Output is correct
16 Correct 7 ms 208 KB Output is correct
17 Correct 8 ms 208 KB Output is correct
18 Correct 7 ms 300 KB Output is correct
19 Correct 6 ms 304 KB Output is correct
20 Correct 5 ms 300 KB Output is correct
21 Correct 4 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 0 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 6 ms 208 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 4 ms 208 KB Output is correct
9 Correct 5 ms 296 KB Output is correct
10 Correct 7 ms 208 KB Output is correct
11 Correct 3 ms 208 KB Output is correct
12 Correct 6 ms 208 KB Output is correct
13 Correct 7 ms 208 KB Output is correct
14 Correct 4 ms 300 KB Output is correct
15 Correct 8 ms 208 KB Output is correct
16 Correct 7 ms 208 KB Output is correct
17 Correct 8 ms 208 KB Output is correct
18 Correct 7 ms 300 KB Output is correct
19 Correct 6 ms 304 KB Output is correct
20 Correct 5 ms 300 KB Output is correct
21 Correct 4 ms 208 KB Output is correct
22 Correct 2 ms 208 KB Output is correct
23 Correct 30 ms 300 KB Output is correct
24 Correct 9 ms 332 KB Output is correct
25 Correct 33 ms 312 KB Output is correct
26 Correct 39 ms 336 KB Output is correct
27 Correct 21 ms 292 KB Output is correct
28 Correct 5 ms 320 KB Output is correct
29 Correct 23 ms 292 KB Output is correct
30 Correct 21 ms 416 KB Output is correct
31 Correct 23 ms 288 KB Output is correct
32 Correct 38 ms 536 KB Output is correct
33 Correct 53 ms 540 KB Output is correct
34 Correct 50 ms 320 KB Output is correct
35 Correct 29 ms 288 KB Output is correct
36 Correct 38 ms 300 KB Output is correct
37 Correct 39 ms 312 KB Output is correct
38 Correct 30 ms 300 KB Output is correct
39 Correct 24 ms 296 KB Output is correct
40 Correct 17 ms 316 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 1 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 0 ms 208 KB Output is correct
7 Correct 56 ms 368 KB Output is correct
8 Correct 23 ms 460 KB Output is correct
9 Correct 50 ms 452 KB Output is correct
10 Partially correct 70 ms 324 KB Output is partially correct
11 Correct 51 ms 404 KB Output is correct
12 Correct 27 ms 320 KB Output is correct
13 Correct 40 ms 288 KB Output is correct
14 Partially correct 68 ms 332 KB Output is partially correct
15 Partially correct 114 ms 460 KB Output is partially correct
16 Partially correct 100 ms 452 KB Output is partially correct
17 Partially correct 116 ms 452 KB Output is partially correct
18 Partially correct 95 ms 456 KB Output is partially correct
19 Partially correct 65 ms 416 KB Output is partially correct
20 Partially correct 76 ms 440 KB Output is partially correct
21 Partially correct 83 ms 428 KB Output is partially correct
22 Partially correct 71 ms 280 KB Output is partially correct
23 Partially correct 61 ms 416 KB Output is partially correct
24 Correct 40 ms 308 KB Output is correct
25 Correct 27 ms 328 KB Output is correct
26 Correct 22 ms 324 KB Output is correct
27 Correct 63 ms 296 KB Output is correct
28 Correct 34 ms 284 KB Output is correct
29 Correct 63 ms 276 KB Output is correct
30 Correct 36 ms 276 KB Output is correct
31 Partially correct 80 ms 300 KB Output is partially correct
32 Partially correct 47 ms 292 KB Output is partially correct
33 Partially correct 58 ms 372 KB Output is partially correct
34 Partially correct 55 ms 336 KB Output is partially correct
35 Correct 51 ms 412 KB Output is correct
36 Correct 49 ms 304 KB Output is correct
37 Partially correct 79 ms 524 KB Output is partially correct
38 Partially correct 78 ms 424 KB Output is partially correct
39 Correct 53 ms 368 KB Output is correct
40 Correct 54 ms 360 KB Output is correct
41 Correct 57 ms 328 KB Output is correct
42 Correct 59 ms 368 KB Output is correct
43 Correct 12 ms 300 KB Output is correct
44 Correct 26 ms 208 KB Output is correct
45 Correct 31 ms 276 KB Output is correct
46 Correct 23 ms 288 KB Output is correct
47 Correct 15 ms 308 KB Output is correct
48 Correct 32 ms 308 KB Output is correct