Submission #1085472

# Submission time Handle Problem Language Result Execution time Memory
1085472 2024-09-08T10:02:07 Z SamueleVid Rarest Insects (IOI22_insects) C++17
54.87 / 100
112 ms 1232 KB
#include <bits/stdc++.h>
using namespace std;

void move_inside(int i);
void move_outside(int i);
int press_button();

vector<int> sol(vector<int> types, vector<int> usable, int l, int r) {
    // cout << "types : ";
    // for (auto x : types) cout << x << " ";
    // cout << '\n';
    // cout << "usable : ";
    // for (auto x : usable) cout << x << " ";
    // cout << '\n';

    vector<int> res;
    if (types.size() == 0) {
        return {};
    }
    if (types.size() == 1) {
        res.push_back(usable.size() + 1);
        return res;
    }
    vector<int> sx, dx;


    int trg = (l + r) / 2;
    
    for (auto i : usable) {
        if (i < trg) sx.push_back(i);
        else dx.push_back(i);
    }

    vector<int> types_sx, types_dx;
    for (auto x : types) {
        if (x < trg) types_sx.push_back(x);
        if (x >= trg) types_dx.push_back(x);
    }

    if (types_sx.empty()) {
        return sol(types, usable, trg, r);
    }
    if (types_dx.empty()) {
        return sol(types, usable, l, trg);
    }

    // cout << "mezzo : " << types[types.size() / 2] << '\n';
    // cout << "dx : ";
    // for (auto x : dx) cout << x << " ";
    // cout << '\n'; 
    // cout << "type_dx : ";
    // for (auto x : types_dx) cout << x << " ";
    // cout << '\n'; 

    vector<int> pusha_sx = sx;
    vector<int> pusha_dx;
    for (auto x : types_dx) move_inside(x);
    for (auto x : dx) {
        move_inside(x);
        if (press_button() == 2) { // fa parte dei gruppi
            pusha_dx.push_back(x);
        }
        else { // == 1, è dei gruppi a sinistra
            pusha_sx.push_back(x);
        }
        move_outside(x);
    }
    for (auto x : types_dx) move_outside(x);

    vector<int> res_sx = sol(types_sx, pusha_sx, l, trg);
    vector<int> res_dx = sol(types_dx, pusha_dx, trg, r);
    for (auto x : res_sx) res.push_back(x);
    for (auto x : res_dx) res.push_back(x);

    return res;
}

int min_cardinality(int N) {
    // il primo elemento di tutti i gruppi
    vector<int> types;
    for (int i = 0; i < N; i ++) {
        move_inside(i);
        if (press_button() > 1) {
            move_outside(i);
            continue;
        }
        types.push_back(i);
    }
    for (auto x : types) move_outside(x);

    set<int> types_set;
    for (auto x : types) types_set.insert(x);

    vector<int> usable;
    for (int i = 0; i < N; i ++) if (!types_set.count(i)) usable.push_back(i);
    vector<int> res = sol(types, usable, 0, N);

    int minim = N;
    for (auto x : res) minim = min(minim, x);

    return minim;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 596 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 6 ms 600 KB Output is correct
9 Correct 5 ms 344 KB Output is correct
10 Correct 2 ms 344 KB Output is correct
11 Correct 4 ms 456 KB Output is correct
12 Correct 4 ms 344 KB Output is correct
13 Correct 5 ms 436 KB Output is correct
14 Correct 3 ms 600 KB Output is correct
15 Correct 5 ms 440 KB Output is correct
16 Correct 5 ms 444 KB Output is correct
17 Correct 3 ms 344 KB Output is correct
18 Correct 7 ms 700 KB Output is correct
19 Correct 7 ms 344 KB Output is correct
20 Correct 6 ms 432 KB Output is correct
21 Correct 5 ms 344 KB Output is correct
22 Correct 4 ms 456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 596 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 6 ms 600 KB Output is correct
9 Correct 5 ms 344 KB Output is correct
10 Correct 2 ms 344 KB Output is correct
11 Correct 4 ms 456 KB Output is correct
12 Correct 4 ms 344 KB Output is correct
13 Correct 5 ms 436 KB Output is correct
14 Correct 3 ms 600 KB Output is correct
15 Correct 5 ms 440 KB Output is correct
16 Correct 5 ms 444 KB Output is correct
17 Correct 3 ms 344 KB Output is correct
18 Correct 7 ms 700 KB Output is correct
19 Correct 7 ms 344 KB Output is correct
20 Correct 6 ms 432 KB Output is correct
21 Correct 5 ms 344 KB Output is correct
22 Correct 4 ms 456 KB Output is correct
23 Correct 5 ms 344 KB Output is correct
24 Correct 6 ms 448 KB Output is correct
25 Correct 33 ms 480 KB Output is correct
26 Correct 34 ms 496 KB Output is correct
27 Correct 7 ms 344 KB Output is correct
28 Correct 23 ms 592 KB Output is correct
29 Correct 17 ms 756 KB Output is correct
30 Correct 52 ms 704 KB Output is correct
31 Correct 15 ms 432 KB Output is correct
32 Correct 25 ms 432 KB Output is correct
33 Correct 22 ms 728 KB Output is correct
34 Correct 22 ms 492 KB Output is correct
35 Correct 33 ms 600 KB Output is correct
36 Correct 39 ms 740 KB Output is correct
37 Correct 33 ms 476 KB Output is correct
38 Correct 45 ms 724 KB Output is correct
39 Correct 48 ms 668 KB Output is correct
40 Correct 26 ms 596 KB Output is correct
41 Correct 25 ms 616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 9 ms 432 KB Output is correct
8 Partially correct 15 ms 696 KB Output is partially correct
9 Partially correct 93 ms 672 KB Output is partially correct
10 Partially correct 78 ms 704 KB Output is partially correct
11 Correct 23 ms 596 KB Output is correct
12 Partially correct 65 ms 600 KB Output is partially correct
13 Partially correct 34 ms 452 KB Output is partially correct
14 Partially correct 106 ms 864 KB Output is partially correct
15 Partially correct 28 ms 568 KB Output is partially correct
16 Partially correct 64 ms 728 KB Output is partially correct
17 Partially correct 47 ms 852 KB Output is partially correct
18 Partially correct 73 ms 772 KB Output is partially correct
19 Partially correct 66 ms 820 KB Output is partially correct
20 Partially correct 84 ms 824 KB Output is partially correct
21 Partially correct 89 ms 496 KB Output is partially correct
22 Partially correct 91 ms 600 KB Output is partially correct
23 Partially correct 112 ms 1232 KB Output is partially correct
24 Partially correct 89 ms 744 KB Output is partially correct
25 Partially correct 86 ms 1000 KB Output is partially correct
26 Partially correct 59 ms 552 KB Output is partially correct
27 Partially correct 87 ms 668 KB Output is partially correct
28 Partially correct 89 ms 924 KB Output is partially correct
29 Partially correct 79 ms 688 KB Output is partially correct
30 Partially correct 72 ms 688 KB Output is partially correct
31 Partially correct 84 ms 848 KB Output is partially correct
32 Partially correct 68 ms 824 KB Output is partially correct
33 Partially correct 71 ms 1032 KB Output is partially correct
34 Partially correct 79 ms 548 KB Output is partially correct
35 Partially correct 72 ms 592 KB Output is partially correct
36 Partially correct 94 ms 780 KB Output is partially correct
37 Partially correct 90 ms 720 KB Output is partially correct
38 Partially correct 72 ms 772 KB Output is partially correct
39 Partially correct 75 ms 592 KB Output is partially correct
40 Partially correct 82 ms 560 KB Output is partially correct
41 Partially correct 86 ms 812 KB Output is partially correct
42 Partially correct 83 ms 940 KB Output is partially correct
43 Partially correct 18 ms 688 KB Output is partially correct
44 Partially correct 36 ms 684 KB Output is partially correct
45 Correct 23 ms 672 KB Output is correct
46 Partially correct 10 ms 600 KB Output is partially correct
47 Partially correct 74 ms 708 KB Output is partially correct
48 Partially correct 17 ms 436 KB Output is partially correct