Submission #641229

# Submission time Handle Problem Language Result Execution time Memory
641229 2022-09-16T08:42:05 Z SlavicG Rarest Insects (IOI22_insects) C++17
100 / 100
415 ms 416 KB
#include "insects.h"
#include "bits/stdc++.h"
using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int min_cardinality(int n) {

    vector<int> a;
    int cnt = 0;
    cnt = 1;
    move_inside(0);
    a.push_back(0);
    vector<int> types = {0};
    for(int i = 1; i < n; ++i) {
        a.push_back(i);
        move_inside(i);
        if(press_button() == 1) {
            ++cnt;
            types.push_back(i);
        } else {
            move_outside(a.back());
            a.pop_back();
        }
    }
    while(!a.empty()) {
        move_outside(a.back());
        a.pop_back();
    }

    vector<int> frfr(n);
    for(int i = 0; i < n; ++i) frfr[i] = i;
    shuffle(frfr.begin(), frfr.end(), rng);
    int ans = -1, l = 1, r = n / cnt;
    while(l <= r) {
        int mid = l + r >> 1;
        vector<int> added;
        for(int i: frfr) {
            sort(a.begin(), a.end());
            int idx = lower_bound(a.begin(), a.end(), i) - a.begin();
            if(idx < (int)a.size() && a[idx] == i) continue;
            move_inside(i);
            a.push_back(i);
            added.push_back(i);
            if(press_button() > mid) {
                added.pop_back();
                a.pop_back();
                move_outside(i);
            }
            if((int)a.size() == cnt * mid) break;
        }

        if((int)a.size() == mid * cnt) {
            ans = mid;
            l = mid + 1;
        } else {
            r = mid - 1;
            if(l <= r) {
                frfr = added;
                for(int i: added) {
                    sort(a.begin(), a.end());
                    move_outside(i);
                    int idx = lower_bound(a.begin(), a.end(), i) - a.begin();
                    assert(a[idx] == i);
                    a.erase(a.begin() + idx);
                }
            }
        }
    }
    return ans;

}

Compilation message

insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:36:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   36 |         int mid = l + r >> 1;
      |                   ~~^~~
# 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 0 ms 216 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 6 ms 300 KB Output is correct
7 Correct 6 ms 208 KB Output is correct
8 Correct 6 ms 304 KB Output is correct
9 Correct 6 ms 304 KB Output is correct
10 Correct 6 ms 208 KB Output is correct
11 Correct 5 ms 208 KB Output is correct
12 Correct 7 ms 208 KB Output is correct
13 Correct 8 ms 300 KB Output is correct
14 Correct 7 ms 304 KB Output is correct
15 Correct 5 ms 308 KB Output is correct
16 Correct 6 ms 208 KB Output is correct
17 Correct 7 ms 208 KB Output is correct
18 Correct 7 ms 304 KB Output is correct
19 Correct 9 ms 328 KB Output is correct
20 Correct 5 ms 208 KB Output is correct
21 Correct 6 ms 300 KB Output is correct
22 Correct 4 ms 256 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 0 ms 216 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 6 ms 300 KB Output is correct
7 Correct 6 ms 208 KB Output is correct
8 Correct 6 ms 304 KB Output is correct
9 Correct 6 ms 304 KB Output is correct
10 Correct 6 ms 208 KB Output is correct
11 Correct 5 ms 208 KB Output is correct
12 Correct 7 ms 208 KB Output is correct
13 Correct 8 ms 300 KB Output is correct
14 Correct 7 ms 304 KB Output is correct
15 Correct 5 ms 308 KB Output is correct
16 Correct 6 ms 208 KB Output is correct
17 Correct 7 ms 208 KB Output is correct
18 Correct 7 ms 304 KB Output is correct
19 Correct 9 ms 328 KB Output is correct
20 Correct 5 ms 208 KB Output is correct
21 Correct 6 ms 300 KB Output is correct
22 Correct 4 ms 256 KB Output is correct
23 Correct 108 ms 300 KB Output is correct
24 Correct 36 ms 308 KB Output is correct
25 Correct 84 ms 292 KB Output is correct
26 Correct 55 ms 308 KB Output is correct
27 Correct 23 ms 212 KB Output is correct
28 Correct 19 ms 308 KB Output is correct
29 Correct 41 ms 300 KB Output is correct
30 Correct 32 ms 304 KB Output is correct
31 Correct 49 ms 320 KB Output is correct
32 Correct 66 ms 296 KB Output is correct
33 Correct 46 ms 300 KB Output is correct
34 Correct 51 ms 296 KB Output is correct
35 Correct 57 ms 296 KB Output is correct
36 Correct 48 ms 208 KB Output is correct
37 Correct 55 ms 292 KB Output is correct
38 Correct 43 ms 308 KB Output is correct
39 Correct 45 ms 300 KB Output is correct
40 Correct 36 ms 316 KB Output is correct
41 Correct 25 ms 304 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 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 415 ms 308 KB Output is correct
8 Correct 112 ms 344 KB Output is correct
9 Correct 239 ms 304 KB Output is correct
10 Correct 130 ms 328 KB Output is correct
11 Correct 57 ms 208 KB Output is correct
12 Correct 114 ms 312 KB Output is correct
13 Correct 93 ms 300 KB Output is correct
14 Correct 94 ms 284 KB Output is correct
15 Correct 203 ms 412 KB Output is correct
16 Correct 193 ms 308 KB Output is correct
17 Correct 203 ms 288 KB Output is correct
18 Correct 157 ms 208 KB Output is correct
19 Correct 183 ms 312 KB Output is correct
20 Correct 170 ms 300 KB Output is correct
21 Correct 142 ms 304 KB Output is correct
22 Correct 136 ms 312 KB Output is correct
23 Correct 100 ms 300 KB Output is correct
24 Correct 82 ms 308 KB Output is correct
25 Correct 101 ms 312 KB Output is correct
26 Correct 65 ms 316 KB Output is correct
27 Correct 232 ms 308 KB Output is correct
28 Correct 225 ms 304 KB Output is correct
29 Correct 253 ms 288 KB Output is correct
30 Correct 254 ms 300 KB Output is correct
31 Correct 118 ms 296 KB Output is correct
32 Correct 125 ms 304 KB Output is correct
33 Correct 90 ms 300 KB Output is correct
34 Correct 83 ms 296 KB Output is correct
35 Correct 239 ms 284 KB Output is correct
36 Correct 252 ms 308 KB Output is correct
37 Correct 193 ms 304 KB Output is correct
38 Correct 133 ms 304 KB Output is correct
39 Correct 211 ms 288 KB Output is correct
40 Correct 229 ms 308 KB Output is correct
41 Correct 256 ms 308 KB Output is correct
42 Correct 261 ms 316 KB Output is correct
43 Correct 10 ms 208 KB Output is correct
44 Correct 36 ms 296 KB Output is correct
45 Correct 408 ms 304 KB Output is correct
46 Correct 78 ms 312 KB Output is correct
47 Correct 73 ms 312 KB Output is correct
48 Correct 92 ms 416 KB Output is correct