Submission #633917

# Submission time Handle Problem Language Result Execution time Memory
633917 2022-08-23T12:52:49 Z Kirill22 Rarest Insects (IOI22_insects) C++17
100 / 100
66 ms 440 KB
#include<bits/stdc++.h>
 
using namespace std;
 
void move_inside(int i);
void move_outside(int i);
int press_button();
 
int min_cardinality(int n) {
    mt19937 gen(22);
    vector<int> ord(n);
    iota(ord.begin(), ord.end(), 0);
    shuffle(ord.begin(), ord.end(), gen);
    vector<int> used(n);
    for (auto i : ord) {
        move_inside(i);
        if (press_button() >= 2) {
            move_outside(i);
        } else {
            used[i] = 1;
        }
    }
    int cnt = accumulate(used.begin(), used.end(), 0);
    if (cnt == 1) {
        return n;
    }
    int l = 1, r = n / cnt + 1;
    auto start = used;
    vector<int> ban(n);
    while (l + 1 < r) {
        int m = (l + r) / 2;
        for (auto i : ord) {
            if (used[i] && !start[i]) {
                used[i] = 0;
                move_outside(i);
            }
        }
        vector<int> b;
      	int cnt2 = accumulate(used.begin(), used.end(), 0);
        for (auto i : ord) {
            if (!used[i] && !ban[i]) {
                move_inside(i);
                int res = press_button();
                if (res >= m + 1) {
                    move_outside(i);
                    b.push_back(i);
                } else {
                    used[i] = 1;
                  	cnt2++;
                  	if (cnt2 == m * cnt) {
                      	break;
                    }
                }
            }
        }
        //cout << m << " " << cnt2 << endl;
        //for (auto x : used) cout << x << " "; cout << endl;
        //for (auto x : ban) cout << x << " "; cout << endl;
        if (m * cnt == cnt2) {
            l = m;
            start = used;
        } else {
            r = m;
            for (auto i : b) {
                ban[i] = 1;
            }
        }
    }
    return l;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 280 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 3 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 6 ms 208 KB Output is correct
9 Correct 4 ms 300 KB Output is correct
10 Correct 6 ms 208 KB Output is correct
11 Correct 3 ms 208 KB Output is correct
12 Correct 7 ms 208 KB Output is correct
13 Correct 5 ms 300 KB Output is correct
14 Correct 5 ms 208 KB Output is correct
15 Correct 4 ms 208 KB Output is correct
16 Correct 6 ms 208 KB Output is correct
17 Correct 7 ms 208 KB Output is correct
18 Correct 3 ms 208 KB Output is correct
19 Correct 5 ms 208 KB Output is correct
20 Correct 4 ms 208 KB Output is correct
21 Correct 4 ms 208 KB Output is correct
22 Correct 3 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 280 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 3 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 6 ms 208 KB Output is correct
9 Correct 4 ms 300 KB Output is correct
10 Correct 6 ms 208 KB Output is correct
11 Correct 3 ms 208 KB Output is correct
12 Correct 7 ms 208 KB Output is correct
13 Correct 5 ms 300 KB Output is correct
14 Correct 5 ms 208 KB Output is correct
15 Correct 4 ms 208 KB Output is correct
16 Correct 6 ms 208 KB Output is correct
17 Correct 7 ms 208 KB Output is correct
18 Correct 3 ms 208 KB Output is correct
19 Correct 5 ms 208 KB Output is correct
20 Correct 4 ms 208 KB Output is correct
21 Correct 4 ms 208 KB Output is correct
22 Correct 3 ms 208 KB Output is correct
23 Correct 9 ms 208 KB Output is correct
24 Correct 10 ms 208 KB Output is correct
25 Correct 21 ms 208 KB Output is correct
26 Correct 30 ms 208 KB Output is correct
27 Correct 15 ms 208 KB Output is correct
28 Correct 10 ms 208 KB Output is correct
29 Correct 29 ms 300 KB Output is correct
30 Correct 24 ms 208 KB Output is correct
31 Correct 19 ms 208 KB Output is correct
32 Correct 22 ms 208 KB Output is correct
33 Correct 34 ms 208 KB Output is correct
34 Correct 25 ms 208 KB Output is correct
35 Correct 23 ms 308 KB Output is correct
36 Correct 21 ms 208 KB Output is correct
37 Correct 29 ms 300 KB Output is correct
38 Correct 18 ms 208 KB Output is correct
39 Correct 19 ms 312 KB Output is correct
40 Correct 17 ms 208 KB Output is correct
41 Correct 8 ms 312 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 1 ms 208 KB Output is correct
7 Correct 16 ms 208 KB Output is correct
8 Correct 18 ms 308 KB Output is correct
9 Correct 40 ms 320 KB Output is correct
10 Correct 57 ms 300 KB Output is correct
11 Correct 49 ms 316 KB Output is correct
12 Correct 26 ms 320 KB Output is correct
13 Correct 45 ms 312 KB Output is correct
14 Correct 57 ms 312 KB Output is correct
15 Correct 52 ms 312 KB Output is correct
16 Correct 47 ms 312 KB Output is correct
17 Correct 45 ms 208 KB Output is correct
18 Correct 41 ms 316 KB Output is correct
19 Correct 56 ms 316 KB Output is correct
20 Correct 33 ms 296 KB Output is correct
21 Correct 55 ms 312 KB Output is correct
22 Correct 43 ms 296 KB Output is correct
23 Correct 42 ms 312 KB Output is correct
24 Correct 31 ms 300 KB Output is correct
25 Correct 17 ms 312 KB Output is correct
26 Correct 23 ms 208 KB Output is correct
27 Correct 38 ms 312 KB Output is correct
28 Correct 42 ms 312 KB Output is correct
29 Correct 38 ms 308 KB Output is correct
30 Correct 48 ms 308 KB Output is correct
31 Correct 51 ms 296 KB Output is correct
32 Correct 45 ms 308 KB Output is correct
33 Correct 49 ms 440 KB Output is correct
34 Correct 39 ms 316 KB Output is correct
35 Correct 29 ms 316 KB Output is correct
36 Correct 23 ms 312 KB Output is correct
37 Correct 25 ms 296 KB Output is correct
38 Correct 55 ms 308 KB Output is correct
39 Correct 24 ms 312 KB Output is correct
40 Correct 42 ms 296 KB Output is correct
41 Correct 66 ms 316 KB Output is correct
42 Correct 51 ms 312 KB Output is correct
43 Correct 15 ms 308 KB Output is correct
44 Correct 35 ms 312 KB Output is correct
45 Correct 35 ms 208 KB Output is correct
46 Correct 32 ms 312 KB Output is correct
47 Correct 30 ms 296 KB Output is correct
48 Correct 29 ms 320 KB Output is correct