Submission #1074647

# Submission time Handle Problem Language Result Execution time Memory
1074647 2024-08-25T11:40:25 Z Nicolaikrob Rarest Insects (IOI22_insects) C++17
99.89 / 100
55 ms 1212 KB
#include "insects.h"
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;

int n, tc, il, rc = 0;
set<int> M, IU;
vi IS;

void mi(int i) {
    move_inside(IS[i]);
    M.insert(i);
}

void mo(int i) {
    move_outside(IS[i]);
    M.erase(i);
}

int pb() {
    return press_button()+rc;
}

void rm(bool t) {
    if(t) {
        for(auto x : M) {
            IU.erase(x);
            move_outside(IS[x]);
        }
        il -= M.size();
        rc += M.size()/tc;
        M.clear();
    }
    else {
        IU = M;
        il = M.size();
        for(auto x : M)
            move_outside(IS[x]);
        M.clear();
    }
}

bool tjek(int g) {
    for(auto i : IU) {
        mi(i);
        if(pb() > g) mo(i);
    }
    bool s = (int(M.size())+rc*tc == tc*g);
    rm(s);
    return s;
}

int min_cardinality(int N) {
    il = n = N;
    IS.resize(n);
    for(int i = 0; i < n; i++)
        IS[i] = i;
    srand(time(NULL));
    random_shuffle(IS.begin(), IS.end());
    mi(0);
    for(int i = 1; i < n; i++) {
        mi(i);
        if(pb() > 1) mo(i);
    }
    tc = M.size();
    for(int i = 0; i < n; i++)
        IU.insert(i);
    rm(1);
    int l = 1, u = n/tc;
    while(l < u) {
        int mx = 0, g = (l+u+1)/2;
        for(int i = l+1; i <= u; i++) {
            int t = min(tc*(i-rc), il-tc*(i-rc)+1);
            if(t > mx)
                mx = t, g = i;
        }
        if(tjek(g)) l = g;
        else u = g-1;
    }
    return l;
}


/*
12
3 3 3 4 4 4 4 5 5 5 5 4

11
1 3 3 7 1 3 5 7 5 1 3
*/
# 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 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 4 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 3 ms 344 KB Output is correct
9 Correct 5 ms 344 KB Output is correct
10 Correct 3 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 2 ms 344 KB Output is correct
13 Correct 4 ms 344 KB Output is correct
14 Correct 3 ms 344 KB Output is correct
15 Correct 2 ms 344 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 2 ms 344 KB Output is correct
18 Correct 3 ms 344 KB Output is correct
19 Correct 2 ms 344 KB Output is correct
20 Correct 4 ms 344 KB Output is correct
21 Correct 2 ms 344 KB Output is correct
22 Correct 1 ms 344 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 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 4 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 3 ms 344 KB Output is correct
9 Correct 5 ms 344 KB Output is correct
10 Correct 3 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 2 ms 344 KB Output is correct
13 Correct 4 ms 344 KB Output is correct
14 Correct 3 ms 344 KB Output is correct
15 Correct 2 ms 344 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 2 ms 344 KB Output is correct
18 Correct 3 ms 344 KB Output is correct
19 Correct 2 ms 344 KB Output is correct
20 Correct 4 ms 344 KB Output is correct
21 Correct 2 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 15 ms 344 KB Output is correct
24 Correct 5 ms 344 KB Output is correct
25 Correct 16 ms 344 KB Output is correct
26 Correct 22 ms 492 KB Output is correct
27 Correct 7 ms 344 KB Output is correct
28 Correct 4 ms 344 KB Output is correct
29 Correct 12 ms 504 KB Output is correct
30 Correct 12 ms 344 KB Output is correct
31 Correct 12 ms 440 KB Output is correct
32 Correct 22 ms 436 KB Output is correct
33 Correct 18 ms 692 KB Output is correct
34 Correct 12 ms 344 KB Output is correct
35 Correct 13 ms 440 KB Output is correct
36 Correct 10 ms 340 KB Output is correct
37 Correct 15 ms 600 KB Output is correct
38 Correct 12 ms 344 KB Output is correct
39 Correct 13 ms 444 KB Output is correct
40 Correct 10 ms 444 KB Output is correct
41 Correct 6 ms 448 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 30 ms 564 KB Output is correct
8 Correct 15 ms 712 KB Output is correct
9 Correct 42 ms 444 KB Output is correct
10 Correct 41 ms 348 KB Output is correct
11 Correct 23 ms 600 KB Output is correct
12 Correct 10 ms 476 KB Output is correct
13 Correct 22 ms 344 KB Output is correct
14 Correct 30 ms 436 KB Output is correct
15 Correct 28 ms 344 KB Output is correct
16 Correct 38 ms 592 KB Output is correct
17 Correct 48 ms 680 KB Output is correct
18 Correct 48 ms 1212 KB Output is correct
19 Partially correct 38 ms 676 KB Output is partially correct
20 Correct 31 ms 344 KB Output is correct
21 Correct 55 ms 696 KB Output is correct
22 Correct 29 ms 344 KB Output is correct
23 Correct 31 ms 704 KB Output is correct
24 Correct 25 ms 600 KB Output is correct
25 Correct 14 ms 600 KB Output is correct
26 Correct 11 ms 600 KB Output is correct
27 Correct 27 ms 680 KB Output is correct
28 Correct 42 ms 520 KB Output is correct
29 Partially correct 29 ms 344 KB Output is partially correct
30 Partially correct 35 ms 424 KB Output is partially correct
31 Correct 31 ms 436 KB Output is correct
32 Correct 25 ms 344 KB Output is correct
33 Correct 21 ms 340 KB Output is correct
34 Correct 40 ms 592 KB Output is correct
35 Partially correct 29 ms 344 KB Output is partially correct
36 Partially correct 44 ms 592 KB Output is partially correct
37 Correct 49 ms 440 KB Output is correct
38 Correct 30 ms 592 KB Output is correct
39 Correct 24 ms 344 KB Output is correct
40 Correct 39 ms 436 KB Output is correct
41 Partially correct 46 ms 596 KB Output is partially correct
42 Partially correct 44 ms 448 KB Output is partially correct
43 Correct 6 ms 344 KB Output is correct
44 Correct 31 ms 344 KB Output is correct
45 Correct 30 ms 576 KB Output is correct
46 Correct 9 ms 344 KB Output is correct
47 Correct 16 ms 344 KB Output is correct
48 Correct 23 ms 640 KB Output is correct