Submission #652948

# Submission time Handle Problem Language Result Execution time Memory
652948 2022-10-25T08:56:14 Z grt Rarest Insects (IOI22_insects) C++17
100 / 100
61 ms 428 KB
#include "insects.h"
//GRT_2018
#include <bits/stdc++.h>
#define PB push_back
#define ST first
#define ND second
//mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

using namespace std;

using ll = long long;
using pi = pair<int,int>;
using vi = vector<int>;

const int nax = 2010;
bool discarded[nax];

mt19937 rng(104910);
int k, ans;

int baseLength(vi &v) {
        vi taken = {};
        shuffle(v.begin(), v.end(), rng);
        for(int x : v) {
                move_inside(x);
                taken.PB(x);
                int w = press_button();
                if(w >= 2) {
                        move_outside(x);
                        taken.pop_back();
                }
        }
        for(int x : taken) {
                move_outside(x);
                discarded[x] = true;
        }
        return (int)taken.size();
}

bool mark[nax];

void elimination(vi &v, int lim) {
        for(int x : v) mark[x] = false;
        vi taken = {};
        shuffle(v.begin(), v.end(), rng);
        for(int x : v) {
                move_inside(x);
                taken.PB(x);
                if(press_button() > lim) {
                        move_outside(x);
                        taken.pop_back();
                }
                if((int)taken.size() == k * lim) {
                        break;
                }
        }
        for(int x : taken) {
                move_outside(x);
                mark[x] = true;
        }
        if((int)taken.size() == k * lim) {
                for(int x : taken) {
                        discarded[x] = true;
                }
                ans += lim;
        } else {
                for(int x : v) {
                        if(!mark[x]) discarded[x] = true;
                }
        }
}


int min_cardinality(int n) {
        vi allowed = {};
        for(int i = 0; i < n; ++i) {
                allowed.PB(i);
        }
        k = n;
        k = baseLength(allowed);
        ans = 1;
        while(true) {
                allowed = {};
                for(int i = 0; i < n; ++i) {
                        if(!discarded[i]) {
                                allowed.PB(i);
                        }
                }
                if(k > (int)allowed.size()) {
                        return ans;
                }
                int B = (int)allowed.size() / k;
                B /= 2;
                B = max(B, 1);
                elimination(allowed, B);
        }
        return -1;
}
# 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 1 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 208 KB Output is correct
7 Correct 3 ms 208 KB Output is correct
8 Correct 6 ms 208 KB Output is correct
9 Correct 7 ms 208 KB Output is correct
10 Correct 8 ms 208 KB Output is correct
11 Correct 4 ms 208 KB Output is correct
12 Correct 6 ms 208 KB Output is correct
13 Correct 5 ms 208 KB Output is correct
14 Correct 4 ms 208 KB Output is correct
15 Correct 6 ms 208 KB Output is correct
16 Correct 5 ms 208 KB Output is correct
17 Correct 6 ms 208 KB Output is correct
18 Correct 5 ms 208 KB Output is correct
19 Correct 4 ms 208 KB Output is correct
20 Correct 6 ms 208 KB Output is correct
21 Correct 3 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 1 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 208 KB Output is correct
7 Correct 3 ms 208 KB Output is correct
8 Correct 6 ms 208 KB Output is correct
9 Correct 7 ms 208 KB Output is correct
10 Correct 8 ms 208 KB Output is correct
11 Correct 4 ms 208 KB Output is correct
12 Correct 6 ms 208 KB Output is correct
13 Correct 5 ms 208 KB Output is correct
14 Correct 4 ms 208 KB Output is correct
15 Correct 6 ms 208 KB Output is correct
16 Correct 5 ms 208 KB Output is correct
17 Correct 6 ms 208 KB Output is correct
18 Correct 5 ms 208 KB Output is correct
19 Correct 4 ms 208 KB Output is correct
20 Correct 6 ms 208 KB Output is correct
21 Correct 3 ms 208 KB Output is correct
22 Correct 3 ms 208 KB Output is correct
23 Correct 19 ms 208 KB Output is correct
24 Correct 8 ms 208 KB Output is correct
25 Correct 29 ms 208 KB Output is correct
26 Correct 26 ms 208 KB Output is correct
27 Correct 17 ms 208 KB Output is correct
28 Correct 10 ms 208 KB Output is correct
29 Correct 21 ms 208 KB Output is correct
30 Correct 12 ms 208 KB Output is correct
31 Correct 25 ms 208 KB Output is correct
32 Correct 25 ms 208 KB Output is correct
33 Correct 24 ms 208 KB Output is correct
34 Correct 20 ms 208 KB Output is correct
35 Correct 19 ms 208 KB Output is correct
36 Correct 11 ms 208 KB Output is correct
37 Correct 36 ms 208 KB Output is correct
38 Correct 28 ms 208 KB Output is correct
39 Correct 26 ms 208 KB Output is correct
40 Correct 17 ms 208 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 1 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 49 ms 300 KB Output is correct
8 Correct 20 ms 320 KB Output is correct
9 Correct 54 ms 304 KB Output is correct
10 Correct 51 ms 208 KB Output is correct
11 Correct 24 ms 300 KB Output is correct
12 Correct 28 ms 208 KB Output is correct
13 Correct 47 ms 208 KB Output is correct
14 Correct 50 ms 300 KB Output is correct
15 Correct 35 ms 208 KB Output is correct
16 Correct 47 ms 296 KB Output is correct
17 Correct 48 ms 428 KB Output is correct
18 Correct 34 ms 208 KB Output is correct
19 Correct 46 ms 332 KB Output is correct
20 Correct 39 ms 300 KB Output is correct
21 Correct 31 ms 300 KB Output is correct
22 Correct 49 ms 300 KB Output is correct
23 Correct 46 ms 308 KB Output is correct
24 Correct 32 ms 208 KB Output is correct
25 Correct 27 ms 208 KB Output is correct
26 Correct 19 ms 316 KB Output is correct
27 Correct 46 ms 296 KB Output is correct
28 Correct 45 ms 208 KB Output is correct
29 Correct 21 ms 304 KB Output is correct
30 Correct 28 ms 300 KB Output is correct
31 Correct 61 ms 300 KB Output is correct
32 Correct 58 ms 296 KB Output is correct
33 Correct 45 ms 208 KB Output is correct
34 Correct 43 ms 208 KB Output is correct
35 Correct 45 ms 300 KB Output is correct
36 Correct 47 ms 300 KB Output is correct
37 Correct 55 ms 208 KB Output is correct
38 Correct 43 ms 304 KB Output is correct
39 Correct 48 ms 296 KB Output is correct
40 Correct 51 ms 208 KB Output is correct
41 Correct 42 ms 208 KB Output is correct
42 Correct 37 ms 424 KB Output is correct
43 Correct 15 ms 208 KB Output is correct
44 Correct 35 ms 208 KB Output is correct
45 Correct 32 ms 208 KB Output is correct
46 Correct 34 ms 304 KB Output is correct
47 Correct 24 ms 324 KB Output is correct
48 Correct 25 ms 304 KB Output is correct