Submission #1025200

# Submission time Handle Problem Language Result Execution time Memory
1025200 2024-07-16T17:21:32 Z vjudge1 Rarest Insects (IOI22_insects) C++17
100 / 100
51 ms 1112 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 1 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 3 ms 344 KB Output is correct
7 Correct 3 ms 340 KB Output is correct
8 Correct 3 ms 344 KB Output is correct
9 Correct 3 ms 344 KB Output is correct
10 Correct 5 ms 344 KB Output is correct
11 Correct 3 ms 344 KB Output is correct
12 Correct 5 ms 448 KB Output is correct
13 Correct 4 ms 344 KB Output is correct
14 Correct 2 ms 344 KB Output is correct
15 Correct 6 ms 600 KB Output is correct
16 Correct 5 ms 344 KB Output is correct
17 Correct 5 ms 344 KB Output is correct
18 Correct 2 ms 444 KB Output is correct
19 Correct 3 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 4 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 1 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 3 ms 344 KB Output is correct
7 Correct 3 ms 340 KB Output is correct
8 Correct 3 ms 344 KB Output is correct
9 Correct 3 ms 344 KB Output is correct
10 Correct 5 ms 344 KB Output is correct
11 Correct 3 ms 344 KB Output is correct
12 Correct 5 ms 448 KB Output is correct
13 Correct 4 ms 344 KB Output is correct
14 Correct 2 ms 344 KB Output is correct
15 Correct 6 ms 600 KB Output is correct
16 Correct 5 ms 344 KB Output is correct
17 Correct 5 ms 344 KB Output is correct
18 Correct 2 ms 444 KB Output is correct
19 Correct 3 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 4 ms 600 KB Output is correct
23 Correct 18 ms 344 KB Output is correct
24 Correct 10 ms 856 KB Output is correct
25 Correct 22 ms 432 KB Output is correct
26 Correct 23 ms 448 KB Output is correct
27 Correct 20 ms 452 KB Output is correct
28 Correct 13 ms 452 KB Output is correct
29 Correct 21 ms 344 KB Output is correct
30 Correct 19 ms 452 KB Output is correct
31 Correct 20 ms 448 KB Output is correct
32 Correct 25 ms 600 KB Output is correct
33 Correct 12 ms 344 KB Output is correct
34 Correct 16 ms 856 KB Output is correct
35 Correct 17 ms 448 KB Output is correct
36 Correct 22 ms 448 KB Output is correct
37 Correct 18 ms 600 KB Output is correct
38 Correct 22 ms 344 KB Output is correct
39 Correct 26 ms 448 KB Output is correct
40 Correct 19 ms 596 KB Output is correct
41 Correct 12 ms 456 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 1 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 0 ms 344 KB Output is correct
7 Correct 43 ms 708 KB Output is correct
8 Correct 29 ms 436 KB Output is correct
9 Correct 43 ms 600 KB Output is correct
10 Correct 50 ms 692 KB Output is correct
11 Correct 35 ms 452 KB Output is correct
12 Correct 35 ms 716 KB Output is correct
13 Correct 45 ms 444 KB Output is correct
14 Correct 48 ms 960 KB Output is correct
15 Correct 36 ms 708 KB Output is correct
16 Correct 40 ms 696 KB Output is correct
17 Correct 35 ms 1112 KB Output is correct
18 Correct 39 ms 696 KB Output is correct
19 Correct 32 ms 436 KB Output is correct
20 Correct 46 ms 684 KB Output is correct
21 Correct 51 ms 956 KB Output is correct
22 Correct 44 ms 600 KB Output is correct
23 Correct 46 ms 856 KB Output is correct
24 Correct 14 ms 452 KB Output is correct
25 Correct 41 ms 700 KB Output is correct
26 Correct 29 ms 700 KB Output is correct
27 Correct 42 ms 440 KB Output is correct
28 Correct 32 ms 600 KB Output is correct
29 Correct 36 ms 708 KB Output is correct
30 Correct 28 ms 596 KB Output is correct
31 Correct 43 ms 684 KB Output is correct
32 Correct 51 ms 940 KB Output is correct
33 Correct 45 ms 704 KB Output is correct
34 Correct 33 ms 460 KB Output is correct
35 Correct 36 ms 696 KB Output is correct
36 Correct 42 ms 600 KB Output is correct
37 Correct 38 ms 596 KB Output is correct
38 Correct 26 ms 452 KB Output is correct
39 Correct 49 ms 948 KB Output is correct
40 Correct 34 ms 712 KB Output is correct
41 Correct 43 ms 704 KB Output is correct
42 Correct 31 ms 448 KB Output is correct
43 Correct 10 ms 344 KB Output is correct
44 Correct 31 ms 856 KB Output is correct
45 Correct 34 ms 692 KB Output is correct
46 Correct 47 ms 856 KB Output is correct
47 Correct 50 ms 688 KB Output is correct
48 Correct 28 ms 700 KB Output is correct