Submission #815507

# Submission time Handle Problem Language Result Execution time Memory
815507 2023-08-08T16:05:34 Z JakobZorz Rarest Insects (IOI22_insects) C++17
100 / 100
54 ms 276 KB
#include"insects.h"
#include<iostream>
#include<vector>
#include<set>
using namespace std;

vector<bool>inside;
vector<bool>dead;
int num_inside;
int n,distinct;

int c_press_button(){
    return press_button();
}

void c_move_inside(int a){
    inside[a]=true;
    num_inside++;
    move_inside(a);
}

void c_move_outside(int a){
    inside[a]=false;
    num_inside--;
    move_outside(a);
}

int get_distinct(){
    for(int i=0;i<n;i++){
        c_move_inside(i);
        if(c_press_button()>1)
            c_move_outside(i);
    }
    
    return num_inside;
}

int min_cardinality(int N){
    n=N;
    inside.resize(n);
    distinct=get_distinct();
    dead=inside;
    
    int f=1;
    int r=N-distinct;
    while(distinct<=r){
        int c=(r+2*distinct-1)/(2*distinct);
        for(int i=0;i<n;i++)
            if(!dead[i]&&inside[i]&&num_inside>distinct*f+c)
                c_move_outside(i);
        for(int i=0;i<n;i++)
            if(!dead[i]&&!inside[i]){
                c_move_inside(i);
                if(c_press_button()>f+c)
                    c_move_outside(i);
            }
        
        if(num_inside==(f+c)*distinct){
            f+=c;
            for(int i=0;i<n;i++)
                if(!dead[i]&&inside[i]){
                    r--;
                    dead[i]=true;
                }
        }else{
            for(int i=0;i<n;i++)
                if(!dead[i]&&!inside[i]){
                    r--;
                    dead[i]=true;
                }
        }
    }
    return f;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 5 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 5 ms 208 KB Output is correct
9 Correct 5 ms 208 KB Output is correct
10 Correct 3 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 6 ms 208 KB Output is correct
13 Correct 5 ms 208 KB Output is correct
14 Correct 5 ms 208 KB Output is correct
15 Correct 4 ms 208 KB Output is correct
16 Correct 2 ms 208 KB Output is correct
17 Correct 4 ms 208 KB Output is correct
18 Correct 5 ms 208 KB Output is correct
19 Correct 2 ms 208 KB Output is correct
20 Correct 3 ms 208 KB Output is correct
21 Correct 4 ms 208 KB Output is correct
22 Correct 2 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 5 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 5 ms 208 KB Output is correct
9 Correct 5 ms 208 KB Output is correct
10 Correct 3 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 6 ms 208 KB Output is correct
13 Correct 5 ms 208 KB Output is correct
14 Correct 5 ms 208 KB Output is correct
15 Correct 4 ms 208 KB Output is correct
16 Correct 2 ms 208 KB Output is correct
17 Correct 4 ms 208 KB Output is correct
18 Correct 5 ms 208 KB Output is correct
19 Correct 2 ms 208 KB Output is correct
20 Correct 3 ms 208 KB Output is correct
21 Correct 4 ms 208 KB Output is correct
22 Correct 2 ms 208 KB Output is correct
23 Correct 32 ms 208 KB Output is correct
24 Correct 5 ms 256 KB Output is correct
25 Correct 31 ms 208 KB Output is correct
26 Correct 18 ms 256 KB Output is correct
27 Correct 18 ms 208 KB Output is correct
28 Correct 7 ms 208 KB Output is correct
29 Correct 11 ms 208 KB Output is correct
30 Correct 19 ms 208 KB Output is correct
31 Correct 26 ms 208 KB Output is correct
32 Correct 19 ms 208 KB Output is correct
33 Correct 19 ms 208 KB Output is correct
34 Correct 25 ms 208 KB Output is correct
35 Correct 25 ms 208 KB Output is correct
36 Correct 26 ms 208 KB Output is correct
37 Correct 18 ms 208 KB Output is correct
38 Correct 21 ms 208 KB Output is correct
39 Correct 19 ms 208 KB Output is correct
40 Correct 7 ms 208 KB Output is correct
41 Correct 10 ms 208 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 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 37 ms 208 KB Output is correct
8 Correct 16 ms 208 KB Output is correct
9 Correct 25 ms 208 KB Output is correct
10 Correct 49 ms 208 KB Output is correct
11 Correct 36 ms 208 KB Output is correct
12 Correct 19 ms 208 KB Output is correct
13 Correct 26 ms 208 KB Output is correct
14 Correct 45 ms 208 KB Output is correct
15 Correct 49 ms 256 KB Output is correct
16 Correct 48 ms 208 KB Output is correct
17 Correct 30 ms 208 KB Output is correct
18 Correct 21 ms 208 KB Output is correct
19 Correct 44 ms 208 KB Output is correct
20 Correct 53 ms 208 KB Output is correct
21 Correct 47 ms 276 KB Output is correct
22 Correct 45 ms 208 KB Output is correct
23 Correct 47 ms 208 KB Output is correct
24 Correct 44 ms 208 KB Output is correct
25 Correct 11 ms 208 KB Output is correct
26 Correct 14 ms 208 KB Output is correct
27 Correct 53 ms 208 KB Output is correct
28 Correct 34 ms 256 KB Output is correct
29 Correct 51 ms 208 KB Output is correct
30 Correct 48 ms 256 KB Output is correct
31 Correct 27 ms 208 KB Output is correct
32 Correct 32 ms 208 KB Output is correct
33 Correct 37 ms 208 KB Output is correct
34 Correct 46 ms 256 KB Output is correct
35 Correct 20 ms 208 KB Output is correct
36 Correct 32 ms 208 KB Output is correct
37 Correct 51 ms 276 KB Output is correct
38 Correct 54 ms 208 KB Output is correct
39 Correct 28 ms 256 KB Output is correct
40 Correct 47 ms 256 KB Output is correct
41 Correct 34 ms 208 KB Output is correct
42 Correct 19 ms 208 KB Output is correct
43 Correct 7 ms 208 KB Output is correct
44 Correct 29 ms 208 KB Output is correct
45 Correct 50 ms 208 KB Output is correct
46 Correct 11 ms 208 KB Output is correct
47 Correct 15 ms 208 KB Output is correct
48 Correct 34 ms 208 KB Output is correct