Submission #1025198

# Submission time Handle Problem Language Result Execution time Memory
1025198 2024-07-16T17:21:04 Z Wansur Rarest Insects (IOI22_insects) C++17
100 / 100
48 ms 944 KB
#include <bits/stdc++.h>
#define ent '\n'

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

using namespace std;
typedef long long ll;
const int maxn = 1e5 + 12;

mt19937 rng(10223431);
bool used[maxn];
vector<int> p, d, a, b;
int n, m, c, cnt;

bool check(int x){
    x -= cnt;
    for(int x:a){
        move_outside(x);
    }
    a.clear();
    b.clear();
    for(int i:p){
        if(used[i]) continue;
        move_inside(i);
        if(press_button() > x){
            move_outside(i);
            b.push_back(i);
        }
        else a.push_back(i);
        if(a.size() == x * m) break;
    }
    if(a.size() == x * m){
        cnt += x;
        for(int x:a){
            used[x] = 1;
            c--;
        }
        return 1;
    }
    for(int x:b){
        used[x] = 1;
        c--;
    }
    return 0;
}

int min_cardinality(int N){
    n = N;
    c = n;
    for(int i=0;i<n;i++){
        p.push_back(i);
        move_inside(i);
        if(press_button() != 1){
            move_outside(i);
        }
        else m++;
    }
    for(int i=0;i<n;i++){
        swap(p[i], p[rng() % n]);
    }
    int ans = 0;
    for(int l = 1, r = n / m; l <= r;){
        int mid = l + r >> 1;
        if(check(mid)){
            ans = mid;
            l = mid + 1;
        }
        else r = mid - 1;
    }
    return ans;
}

Compilation message

insects.cpp: In function 'bool check(int)':
insects.cpp:32:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   32 |         if(a.size() == x * m) break;
      |            ~~~~~~~~~^~~~~~~~
insects.cpp:34:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   34 |     if(a.size() == x * m){
      |        ~~~~~~~~~^~~~~~~~
insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:65:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   65 |         int mid = l + r >> 1;
      |                   ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 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 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 3 ms 344 KB Output is correct
8 Correct 5 ms 344 KB Output is correct
9 Correct 5 ms 344 KB Output is correct
10 Correct 4 ms 344 KB Output is correct
11 Correct 4 ms 344 KB Output is correct
12 Correct 5 ms 344 KB Output is correct
13 Correct 4 ms 344 KB Output is correct
14 Correct 3 ms 340 KB Output is correct
15 Correct 6 ms 596 KB Output is correct
16 Correct 5 ms 344 KB Output is correct
17 Correct 5 ms 344 KB Output is correct
18 Correct 5 ms 600 KB Output is correct
19 Correct 4 ms 344 KB Output is correct
20 Correct 4 ms 344 KB Output is correct
21 Correct 4 ms 344 KB Output is correct
22 Correct 3 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 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 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 3 ms 344 KB Output is correct
8 Correct 5 ms 344 KB Output is correct
9 Correct 5 ms 344 KB Output is correct
10 Correct 4 ms 344 KB Output is correct
11 Correct 4 ms 344 KB Output is correct
12 Correct 5 ms 344 KB Output is correct
13 Correct 4 ms 344 KB Output is correct
14 Correct 3 ms 340 KB Output is correct
15 Correct 6 ms 596 KB Output is correct
16 Correct 5 ms 344 KB Output is correct
17 Correct 5 ms 344 KB Output is correct
18 Correct 5 ms 600 KB Output is correct
19 Correct 4 ms 344 KB Output is correct
20 Correct 4 ms 344 KB Output is correct
21 Correct 4 ms 344 KB Output is correct
22 Correct 3 ms 600 KB Output is correct
23 Correct 17 ms 440 KB Output is correct
24 Correct 6 ms 340 KB Output is correct
25 Correct 20 ms 600 KB Output is correct
26 Correct 21 ms 848 KB Output is correct
27 Correct 17 ms 940 KB Output is correct
28 Correct 12 ms 600 KB Output is correct
29 Correct 17 ms 440 KB Output is correct
30 Correct 21 ms 344 KB Output is correct
31 Correct 20 ms 600 KB Output is correct
32 Correct 13 ms 344 KB Output is correct
33 Correct 21 ms 444 KB Output is correct
34 Correct 23 ms 432 KB Output is correct
35 Correct 23 ms 592 KB Output is correct
36 Correct 18 ms 448 KB Output is correct
37 Correct 11 ms 444 KB Output is correct
38 Correct 18 ms 600 KB Output is correct
39 Correct 24 ms 432 KB Output is correct
40 Correct 16 ms 432 KB Output is correct
41 Correct 10 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 600 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 39 ms 684 KB Output is correct
8 Correct 31 ms 604 KB Output is correct
9 Correct 38 ms 848 KB Output is correct
10 Correct 47 ms 608 KB Output is correct
11 Correct 25 ms 444 KB Output is correct
12 Correct 48 ms 848 KB Output is correct
13 Correct 48 ms 852 KB Output is correct
14 Correct 41 ms 444 KB Output is correct
15 Correct 31 ms 844 KB Output is correct
16 Correct 36 ms 460 KB Output is correct
17 Correct 33 ms 692 KB Output is correct
18 Correct 45 ms 696 KB Output is correct
19 Correct 43 ms 700 KB Output is correct
20 Correct 43 ms 600 KB Output is correct
21 Correct 36 ms 696 KB Output is correct
22 Correct 32 ms 452 KB Output is correct
23 Correct 36 ms 856 KB Output is correct
24 Correct 34 ms 596 KB Output is correct
25 Correct 35 ms 696 KB Output is correct
26 Correct 31 ms 696 KB Output is correct
27 Correct 45 ms 452 KB Output is correct
28 Correct 24 ms 460 KB Output is correct
29 Correct 39 ms 684 KB Output is correct
30 Correct 30 ms 608 KB Output is correct
31 Correct 32 ms 600 KB Output is correct
32 Correct 27 ms 600 KB Output is correct
33 Correct 44 ms 600 KB Output is correct
34 Correct 35 ms 440 KB Output is correct
35 Correct 40 ms 600 KB Output is correct
36 Correct 40 ms 452 KB Output is correct
37 Correct 29 ms 440 KB Output is correct
38 Correct 22 ms 452 KB Output is correct
39 Correct 27 ms 708 KB Output is correct
40 Correct 44 ms 604 KB Output is correct
41 Correct 38 ms 444 KB Output is correct
42 Correct 33 ms 440 KB Output is correct
43 Correct 6 ms 448 KB Output is correct
44 Correct 24 ms 340 KB Output is correct
45 Correct 31 ms 688 KB Output is correct
46 Correct 36 ms 704 KB Output is correct
47 Correct 35 ms 596 KB Output is correct
48 Correct 33 ms 944 KB Output is correct