Submission #1025190

# Submission time Handle Problem Language Result Execution time Memory
1025190 2024-07-16T17:15:38 Z Wansur Rarest Insects (IOI22_insects) C++17
99.56 / 100
45 ms 1012 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;

bool used[maxn];
vector<int> d;
int n, m, c, cnt = 0;

bool check(int x){
    x -= cnt;
    vector<int> a, b;
    for(int i=0;i<n;i++){
        if(used[i]) continue;
        move_inside(i);
        if(press_button() > x){
            move_outside(i);
            b.push_back(i);
        }
        else a.push_back(i);
    }
    for(int x:a){
        move_outside(x);
    }
    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++){
        move_inside(i);
        if(press_button() != 1){
            move_outside(i);
        }
        else d.push_back(i);
    }
    for(int i:d){
        move_outside(i);
    }
    m = d.size();
    int ans = 0;
    for(int l = 1, r = (n + m - 1) / 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:31:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   31 |     if(a.size() == x * m){
      |        ~~~~~~~~~^~~~~~~~
insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:62:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   62 |         int mid = l + r >> 1;
      |                   ~~^~~
# 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 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 3 ms 412 KB Output is correct
7 Correct 2 ms 344 KB Output is correct
8 Correct 3 ms 344 KB Output is correct
9 Correct 3 ms 444 KB Output is correct
10 Correct 3 ms 436 KB Output is correct
11 Correct 4 ms 344 KB Output is correct
12 Correct 3 ms 344 KB Output is correct
13 Correct 2 ms 444 KB Output is correct
14 Correct 3 ms 344 KB Output is correct
15 Correct 3 ms 344 KB Output is correct
16 Correct 4 ms 344 KB Output is correct
17 Correct 3 ms 444 KB Output is correct
18 Correct 3 ms 344 KB Output is correct
19 Correct 4 ms 344 KB Output is correct
20 Correct 2 ms 344 KB Output is correct
21 Correct 3 ms 344 KB Output is correct
22 Correct 3 ms 432 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 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 3 ms 412 KB Output is correct
7 Correct 2 ms 344 KB Output is correct
8 Correct 3 ms 344 KB Output is correct
9 Correct 3 ms 444 KB Output is correct
10 Correct 3 ms 436 KB Output is correct
11 Correct 4 ms 344 KB Output is correct
12 Correct 3 ms 344 KB Output is correct
13 Correct 2 ms 444 KB Output is correct
14 Correct 3 ms 344 KB Output is correct
15 Correct 3 ms 344 KB Output is correct
16 Correct 4 ms 344 KB Output is correct
17 Correct 3 ms 444 KB Output is correct
18 Correct 3 ms 344 KB Output is correct
19 Correct 4 ms 344 KB Output is correct
20 Correct 2 ms 344 KB Output is correct
21 Correct 3 ms 344 KB Output is correct
22 Correct 3 ms 432 KB Output is correct
23 Correct 12 ms 344 KB Output is correct
24 Correct 6 ms 344 KB Output is correct
25 Correct 12 ms 344 KB Output is correct
26 Correct 14 ms 444 KB Output is correct
27 Correct 13 ms 440 KB Output is correct
28 Correct 13 ms 600 KB Output is correct
29 Correct 15 ms 440 KB Output is correct
30 Correct 11 ms 344 KB Output is correct
31 Correct 20 ms 448 KB Output is correct
32 Correct 14 ms 344 KB Output is correct
33 Correct 16 ms 448 KB Output is correct
34 Correct 12 ms 344 KB Output is correct
35 Correct 19 ms 344 KB Output is correct
36 Correct 17 ms 856 KB Output is correct
37 Correct 9 ms 344 KB Output is correct
38 Correct 15 ms 448 KB Output is correct
39 Correct 14 ms 344 KB Output is correct
40 Correct 19 ms 600 KB Output is correct
41 Correct 9 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 28 ms 440 KB Output is correct
8 Correct 17 ms 444 KB Output is correct
9 Correct 21 ms 600 KB Output is correct
10 Correct 41 ms 592 KB Output is correct
11 Correct 23 ms 592 KB Output is correct
12 Correct 24 ms 344 KB Output is correct
13 Correct 23 ms 436 KB Output is correct
14 Correct 43 ms 344 KB Output is correct
15 Correct 27 ms 344 KB Output is correct
16 Correct 26 ms 344 KB Output is correct
17 Correct 35 ms 424 KB Output is correct
18 Correct 33 ms 448 KB Output is correct
19 Partially correct 30 ms 436 KB Output is partially correct
20 Correct 30 ms 444 KB Output is correct
21 Correct 21 ms 344 KB Output is correct
22 Correct 28 ms 344 KB Output is correct
23 Correct 22 ms 344 KB Output is correct
24 Partially correct 34 ms 1012 KB Output is partially correct
25 Correct 35 ms 684 KB Output is correct
26 Correct 19 ms 448 KB Output is correct
27 Correct 30 ms 592 KB Output is correct
28 Correct 27 ms 416 KB Output is correct
29 Correct 44 ms 604 KB Output is correct
30 Correct 39 ms 600 KB Output is correct
31 Correct 45 ms 344 KB Output is correct
32 Correct 30 ms 696 KB Output is correct
33 Correct 33 ms 680 KB Output is correct
34 Correct 38 ms 448 KB Output is correct
35 Correct 37 ms 420 KB Output is correct
36 Correct 26 ms 584 KB Output is correct
37 Correct 42 ms 432 KB Output is correct
38 Correct 34 ms 932 KB Output is correct
39 Correct 22 ms 688 KB Output is correct
40 Correct 27 ms 432 KB Output is correct
41 Correct 18 ms 444 KB Output is correct
42 Correct 34 ms 344 KB Output is correct
43 Correct 7 ms 344 KB Output is correct
44 Correct 21 ms 344 KB Output is correct
45 Correct 34 ms 428 KB Output is correct
46 Correct 16 ms 344 KB Output is correct
47 Correct 25 ms 596 KB Output is correct
48 Correct 23 ms 344 KB Output is correct