Submission #1054776

# Submission time Handle Problem Language Result Execution time Memory
1054776 2024-08-12T12:05:00 Z mc061 Rarest Insects (IOI22_insects) C++17
98.1 / 100
43 ms 700 KB
#include <bits/stdc++.h>
using namespace std;

void move_inside(int i);
void move_outside(int i);
int press_button();

const int mN = 5000;
bool diff[mN]={};

int r[mN]={};

int min_cardinality(int n) {
    srand(time(0));
    iota(r, r+n, 0);
    // random_shuffle(r, r+n);
    vector<int> diffs;
    for (int i = 0; i < n; ++i) {
        move_inside(r[i]);
        diffs.push_back(r[i]);
        int x = press_button();
        if (x == 2) {
            move_outside(r[i]);
            diffs.pop_back();
        }
    }

    int biggest_ans = n/diffs.size();

    for (int i : diffs) move_outside(i), diff[i] = true;

    vector<int> out;
    vector<int> cur_in;
    for (int i = 0; i < n; ++i) {
        if (diff[r[i]]) continue;
        out.push_back(r[i]);
    }

    int cursz = 0;
    auto fill_gap = [&] (int newsz) {
        vector<int> nout;
        for (int i : out) {
            move_inside(i);
            cur_in.push_back(i);
            if (press_button() >= newsz) {
                nout.push_back(i);
                move_outside(i);
                cur_in.pop_back();
            }
        }
        out.swap(nout);
        cursz = newsz;
    };

    int low = 1, high = biggest_ans;
    while (high != low) {
        int mid = (high+low+1) >> 1;
        if (mid < cursz) {
            while (cur_in.size()) {
                out.push_back(cur_in.back());
                move_outside(cur_in.back());
                cur_in.pop_back();
                if (press_button() < mid) break;
            }
            cursz = mid-1;
        }
        fill_gap(mid);
        vector<int> ndiffs;
        for (int j : diffs) {
            move_inside(j);
            if (press_button() < mid) {
                ndiffs.push_back(j);
            }
            move_outside(j);
        }
        if (ndiffs.size() == 0) low = mid;
        else {
            high = mid-1, ndiffs.swap(diffs);
            out.clear();
        }
    }
    return low;
}

/*
90
6 8 2 9 4 4 2 2 8 5 5 2 4 9 10 3 0 7 10 2 3 10 3 5 1 0 4 4 10 1 9 5 6 9 10 9 9 7 1 4 8 8 6 4 3 6 3 2 10 7 0 7 2 10 2 4 4 7 3 0 7 5 9 0 6 9 6 7 9 6 2 4 2 7 3 5 2 9 3 10 5 10 4 1 4 5 7 5 9 8 
ans=4
*/
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 432 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 2 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 3 ms 344 KB Output is correct
9 Correct 3 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 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 2 ms 344 KB Output is correct
15 Correct 1 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 2 ms 344 KB Output is correct
19 Correct 3 ms 344 KB Output is correct
20 Correct 2 ms 344 KB Output is correct
21 Correct 2 ms 344 KB Output is correct
22 Correct 1 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 432 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 2 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 3 ms 344 KB Output is correct
9 Correct 3 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 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 2 ms 344 KB Output is correct
15 Correct 1 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 2 ms 344 KB Output is correct
19 Correct 3 ms 344 KB Output is correct
20 Correct 2 ms 344 KB Output is correct
21 Correct 2 ms 344 KB Output is correct
22 Correct 1 ms 600 KB Output is correct
23 Correct 13 ms 448 KB Output is correct
24 Correct 5 ms 600 KB Output is correct
25 Correct 10 ms 448 KB Output is correct
26 Correct 8 ms 600 KB Output is correct
27 Correct 12 ms 344 KB Output is correct
28 Correct 4 ms 600 KB Output is correct
29 Correct 11 ms 344 KB Output is correct
30 Correct 13 ms 600 KB Output is correct
31 Correct 11 ms 344 KB Output is correct
32 Correct 13 ms 436 KB Output is correct
33 Correct 13 ms 344 KB Output is correct
34 Correct 16 ms 592 KB Output is correct
35 Correct 12 ms 344 KB Output is correct
36 Correct 15 ms 600 KB Output is correct
37 Correct 12 ms 452 KB Output is correct
38 Correct 11 ms 600 KB Output is correct
39 Correct 12 ms 700 KB Output is correct
40 Correct 6 ms 344 KB Output is correct
41 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 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 22 ms 460 KB Output is correct
8 Correct 10 ms 456 KB Output is correct
9 Partially correct 30 ms 600 KB Output is partially correct
10 Partially correct 37 ms 344 KB Output is partially correct
11 Correct 20 ms 696 KB Output is correct
12 Correct 13 ms 456 KB Output is correct
13 Correct 25 ms 444 KB Output is correct
14 Partially correct 31 ms 452 KB Output is partially correct
15 Partially correct 28 ms 452 KB Output is partially correct
16 Partially correct 27 ms 600 KB Output is partially correct
17 Partially correct 30 ms 596 KB Output is partially correct
18 Partially correct 21 ms 680 KB Output is partially correct
19 Partially correct 17 ms 444 KB Output is partially correct
20 Partially correct 31 ms 344 KB Output is partially correct
21 Partially correct 31 ms 344 KB Output is partially correct
22 Partially correct 43 ms 592 KB Output is partially correct
23 Partially correct 23 ms 608 KB Output is partially correct
24 Correct 26 ms 600 KB Output is correct
25 Correct 15 ms 452 KB Output is correct
26 Correct 11 ms 592 KB Output is correct
27 Partially correct 31 ms 444 KB Output is partially correct
28 Partially correct 30 ms 592 KB Output is partially correct
29 Partially correct 24 ms 468 KB Output is partially correct
30 Partially correct 35 ms 592 KB Output is partially correct
31 Correct 22 ms 340 KB Output is correct
32 Partially correct 27 ms 452 KB Output is partially correct
33 Correct 16 ms 344 KB Output is correct
34 Correct 21 ms 448 KB Output is correct
35 Partially correct 19 ms 600 KB Output is partially correct
36 Partially correct 26 ms 444 KB Output is partially correct
37 Correct 19 ms 444 KB Output is correct
38 Correct 13 ms 344 KB Output is correct
39 Correct 23 ms 344 KB Output is correct
40 Correct 31 ms 596 KB Output is correct
41 Partially correct 31 ms 440 KB Output is partially correct
42 Partially correct 23 ms 344 KB Output is partially correct
43 Correct 7 ms 344 KB Output is correct
44 Correct 21 ms 592 KB Output is correct
45 Correct 28 ms 464 KB Output is correct
46 Correct 14 ms 600 KB Output is correct
47 Correct 21 ms 600 KB Output is correct
48 Correct 15 ms 456 KB Output is correct