Submission #1025194

# Submission time Handle Problem Language Result Execution time Memory
1025194 2024-07-16T17:18:06 Z Wansur Rarest Insects (IOI22_insects) C++17
99.64 / 100
48 ms 1108 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;
vector<int> d;
int n, m, c, cnt = 0;

bool check(int x){
    x -= cnt;
    vector<int> a, b;
    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;
    }
    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++){
        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 - 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:29:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   29 |         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 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 4 ms 344 KB Output is correct
7 Correct 2 ms 448 KB Output is correct
8 Correct 4 ms 344 KB Output is correct
9 Correct 3 ms 344 KB Output is correct
10 Correct 3 ms 344 KB Output is correct
11 Correct 3 ms 344 KB Output is correct
12 Correct 4 ms 344 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 3 ms 344 KB Output is correct
15 Correct 3 ms 344 KB Output is correct
16 Correct 3 ms 344 KB Output is correct
17 Correct 3 ms 344 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 444 KB Output is correct
21 Correct 3 ms 344 KB Output is correct
22 Correct 3 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 1 ms 344 KB Output is correct
6 Correct 4 ms 344 KB Output is correct
7 Correct 2 ms 448 KB Output is correct
8 Correct 4 ms 344 KB Output is correct
9 Correct 3 ms 344 KB Output is correct
10 Correct 3 ms 344 KB Output is correct
11 Correct 3 ms 344 KB Output is correct
12 Correct 4 ms 344 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 3 ms 344 KB Output is correct
15 Correct 3 ms 344 KB Output is correct
16 Correct 3 ms 344 KB Output is correct
17 Correct 3 ms 344 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 444 KB Output is correct
21 Correct 3 ms 344 KB Output is correct
22 Correct 3 ms 344 KB Output is correct
23 Correct 18 ms 432 KB Output is correct
24 Correct 13 ms 344 KB Output is correct
25 Correct 13 ms 344 KB Output is correct
26 Correct 24 ms 856 KB Output is correct
27 Correct 8 ms 344 KB Output is correct
28 Correct 16 ms 344 KB Output is correct
29 Correct 13 ms 456 KB Output is correct
30 Correct 14 ms 444 KB Output is correct
31 Correct 18 ms 452 KB Output is correct
32 Correct 19 ms 1108 KB Output is correct
33 Correct 15 ms 344 KB Output is correct
34 Correct 14 ms 596 KB Output is correct
35 Correct 15 ms 600 KB Output is correct
36 Correct 17 ms 456 KB Output is correct
37 Correct 21 ms 600 KB Output is correct
38 Correct 15 ms 704 KB Output is correct
39 Correct 16 ms 344 KB Output is correct
40 Correct 13 ms 592 KB Output is correct
41 Correct 14 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 596 KB Output is correct
2 Correct 0 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 0 ms 344 KB Output is correct
7 Correct 23 ms 468 KB Output is correct
8 Correct 17 ms 592 KB Output is correct
9 Correct 31 ms 344 KB Output is correct
10 Correct 28 ms 692 KB Output is correct
11 Correct 25 ms 448 KB Output is correct
12 Correct 17 ms 344 KB Output is correct
13 Correct 38 ms 592 KB Output is correct
14 Correct 35 ms 600 KB Output is correct
15 Correct 23 ms 344 KB Output is correct
16 Correct 39 ms 456 KB Output is correct
17 Correct 27 ms 592 KB Output is correct
18 Correct 29 ms 448 KB Output is correct
19 Correct 28 ms 600 KB Output is correct
20 Correct 21 ms 344 KB Output is correct
21 Correct 30 ms 692 KB Output is correct
22 Correct 45 ms 592 KB Output is correct
23 Correct 28 ms 344 KB Output is correct
24 Partially correct 38 ms 692 KB Output is partially correct
25 Correct 24 ms 592 KB Output is correct
26 Correct 24 ms 700 KB Output is correct
27 Correct 37 ms 440 KB Output is correct
28 Correct 27 ms 344 KB Output is correct
29 Correct 29 ms 344 KB Output is correct
30 Correct 23 ms 448 KB Output is correct
31 Correct 46 ms 604 KB Output is correct
32 Correct 31 ms 344 KB Output is correct
33 Correct 42 ms 344 KB Output is correct
34 Correct 48 ms 456 KB Output is correct
35 Correct 30 ms 344 KB Output is correct
36 Correct 34 ms 344 KB Output is correct
37 Correct 25 ms 452 KB Output is correct
38 Correct 41 ms 600 KB Output is correct
39 Correct 38 ms 452 KB Output is correct
40 Correct 32 ms 344 KB Output is correct
41 Correct 46 ms 684 KB Output is correct
42 Correct 37 ms 848 KB Output is correct
43 Correct 12 ms 600 KB Output is correct
44 Correct 18 ms 344 KB Output is correct
45 Correct 15 ms 456 KB Output is correct
46 Correct 38 ms 860 KB Output is correct
47 Correct 24 ms 600 KB Output is correct
48 Correct 29 ms 700 KB Output is correct