Submission #1057090

# Submission time Handle Problem Language Result Execution time Memory
1057090 2024-08-13T14:04:16 Z vjudge1 Rarest Insects (IOI22_insects) C++17
99.83 / 100
281 ms 1876 KB
#include "insects.h"
#include <bits/stdc++.h>

using namespace std;

using vi = vector<int>;
using ii = pair<int, int>;

set<int> Cur, Vreau;

void movein2(int v) {
    Vreau.insert(v);
}
void moveout2(int v) {
    Vreau.erase(v);
}

int press2() {
    vi scos, add;
    for(auto it : Cur) {
        if(!Vreau.count(it)) scos.push_back(it);
    }
    for(auto it : Vreau)
        if(!Cur.count(it)) add.push_back(it);
    for(auto it : add) move_inside(it);
    for(auto it : scos) move_outside(it);

    Cur = Vreau;
    return press_button();
}

int min_cardinality(int n) {
    int d = 0;
    vi Cul;
    for(int i = 0; i < n; ++i) {
        movein2(i);
        if(press2() == 1) {
            Cul.push_back(i);
            ++d;
        }
        else moveout2(i);
    }
    for(auto it : Cul) moveout2(it);

    int re = 0;
    int st = 0, dr = n / d, mij;
    set<int> S;
    for(int i = 0; i < n; ++i) S.insert(i);
    while(st < dr) {
        mij = (st + dr + 1) / 2;
        if(d > S.size()) {
            st = dr = 0;
            break; // exista 0!
        }
        set<int> I;
        for(auto it : S) {
            if(I.size() == d * mij) break;
            movein2(it);
            if(press2() == mij + 1) {
                moveout2(it);
            } else {
                I.insert(it);
            }
        }

        if(I.size() == d * mij) {
            for(auto it : I) {
                S.erase(it);
            }
            re += mij;
            st = 0;
            dr = dr - mij;
        } else {
            dr = mij - 1;
            S = I;
        }
        for(auto it : I) moveout2(it);
    }
    return re + st;
}

Compilation message

insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:51:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::set<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |         if(d > S.size()) {
      |            ~~^~~~~~~~~~
insects.cpp:57:25: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   57 |             if(I.size() == d * mij) break;
      |                ~~~~~~~~~^~~~~~~~~~
insects.cpp:66:21: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   66 |         if(I.size() == d * mij) {
      |            ~~~~~~~~~^~~~~~~~~~
# 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 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 2 ms 440 KB Output is correct
7 Correct 5 ms 344 KB Output is correct
8 Correct 4 ms 600 KB Output is correct
9 Correct 5 ms 344 KB Output is correct
10 Correct 2 ms 344 KB Output is correct
11 Correct 2 ms 344 KB Output is correct
12 Correct 2 ms 344 KB Output is correct
13 Correct 3 ms 344 KB Output is correct
14 Correct 4 ms 600 KB Output is correct
15 Correct 3 ms 344 KB Output is correct
16 Correct 4 ms 448 KB Output is correct
17 Correct 3 ms 344 KB Output is correct
18 Correct 4 ms 600 KB Output is correct
19 Correct 4 ms 436 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
21 Correct 6 ms 344 KB Output is correct
22 Correct 4 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 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 2 ms 440 KB Output is correct
7 Correct 5 ms 344 KB Output is correct
8 Correct 4 ms 600 KB Output is correct
9 Correct 5 ms 344 KB Output is correct
10 Correct 2 ms 344 KB Output is correct
11 Correct 2 ms 344 KB Output is correct
12 Correct 2 ms 344 KB Output is correct
13 Correct 3 ms 344 KB Output is correct
14 Correct 4 ms 600 KB Output is correct
15 Correct 3 ms 344 KB Output is correct
16 Correct 4 ms 448 KB Output is correct
17 Correct 3 ms 344 KB Output is correct
18 Correct 4 ms 600 KB Output is correct
19 Correct 4 ms 436 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
21 Correct 6 ms 344 KB Output is correct
22 Correct 4 ms 344 KB Output is correct
23 Correct 12 ms 548 KB Output is correct
24 Correct 54 ms 520 KB Output is correct
25 Correct 18 ms 600 KB Output is correct
26 Correct 26 ms 516 KB Output is correct
27 Correct 20 ms 436 KB Output is correct
28 Correct 26 ms 500 KB Output is correct
29 Correct 24 ms 512 KB Output is correct
30 Correct 29 ms 508 KB Output is correct
31 Correct 18 ms 528 KB Output is correct
32 Correct 18 ms 504 KB Output is correct
33 Correct 24 ms 440 KB Output is correct
34 Correct 22 ms 500 KB Output is correct
35 Correct 17 ms 432 KB Output is correct
36 Correct 18 ms 548 KB Output is correct
37 Correct 22 ms 344 KB Output is correct
38 Correct 33 ms 716 KB Output is correct
39 Correct 36 ms 852 KB Output is correct
40 Correct 28 ms 600 KB Output is correct
41 Correct 29 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 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 37 ms 424 KB Output is correct
8 Correct 281 ms 1000 KB Output is correct
9 Correct 58 ms 844 KB Output is correct
10 Correct 84 ms 844 KB Output is correct
11 Correct 50 ms 344 KB Output is correct
12 Correct 89 ms 588 KB Output is correct
13 Correct 95 ms 664 KB Output is correct
14 Correct 95 ms 592 KB Output is correct
15 Correct 47 ms 664 KB Output is correct
16 Correct 53 ms 600 KB Output is correct
17 Correct 62 ms 852 KB Output is correct
18 Correct 62 ms 648 KB Output is correct
19 Correct 63 ms 592 KB Output is correct
20 Correct 68 ms 592 KB Output is correct
21 Correct 92 ms 648 KB Output is correct
22 Correct 101 ms 676 KB Output is correct
23 Correct 102 ms 848 KB Output is correct
24 Correct 106 ms 1876 KB Output is correct
25 Correct 109 ms 496 KB Output is correct
26 Correct 156 ms 592 KB Output is correct
27 Correct 59 ms 600 KB Output is correct
28 Correct 39 ms 600 KB Output is correct
29 Partially correct 116 ms 544 KB Output is partially correct
30 Partially correct 94 ms 432 KB Output is partially correct
31 Correct 96 ms 600 KB Output is correct
32 Correct 91 ms 676 KB Output is correct
33 Correct 108 ms 676 KB Output is correct
34 Correct 116 ms 832 KB Output is correct
35 Partially correct 113 ms 600 KB Output is partially correct
36 Correct 73 ms 800 KB Output is correct
37 Correct 91 ms 592 KB Output is correct
38 Correct 102 ms 872 KB Output is correct
39 Correct 76 ms 812 KB Output is correct
40 Correct 46 ms 592 KB Output is correct
41 Correct 86 ms 592 KB Output is correct
42 Partially correct 99 ms 676 KB Output is partially correct
43 Correct 9 ms 344 KB Output is correct
44 Correct 34 ms 548 KB Output is correct
45 Correct 60 ms 600 KB Output is correct
46 Correct 81 ms 904 KB Output is correct
47 Correct 83 ms 592 KB Output is correct
48 Correct 91 ms 620 KB Output is correct