Submission #1024476

# Submission time Handle Problem Language Result Execution time Memory
1024476 2024-07-16T05:46:45 Z vjudge1 Rarest Insects (IOI22_insects) C++17
50.3 / 100
106 ms 1256 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;

struct Q{
    int mid, l, r, i;
};

int cnt[maxn];
bool is[maxn];
int p[maxn];

int min_cardinality(int n){
    vector<Q> q;
    vector<int> u;
    for(int i=0;i<n;i++){
        move_inside(i);
        if(press_button() != 1){
            move_outside(i);
            int l = 0, r = (int)u.size() - 1, mid = l + r >> 1;
            q.push_back({mid, l, r, i});
        }
        else{
            u.push_back(i);
            is[i] = 1;
            p[i] = i;
        }
    }
    for(int i=0;i<u.size();i++){
        move_outside(u[i]);
    }
    while(q.size()){
        vector<Q> nq;
        sort(q.begin(), q.end(), [](Q x, Q y){
            return x.mid < y.mid;
        });
        int ptr = 0;
        vector<int> v;
        for(auto [mid, l, r, i]:q){
            while(ptr <= mid){
                v.push_back(u[ptr]);
                move_inside(u[ptr]);
                ptr++;
            }
            move_inside(i);
            if(press_button() != 1){
                r = mid - 1;
                p[i] = u[mid];
            }
            else l = mid + 1;
            move_outside(i);
            if(l <= r){
                int nmid = l + r >> 1;
                nq.push_back({nmid, l, r, i});
            }
        }
        q.swap(nq);
        if(q.size()){
            while(v.size()){
                move_outside(v.back());
                v.pop_back();
            }
        }
    }
    for(int i=0;i<n;i++){
        cnt[p[i]]++;
    }
    int ans = 1e9;
    for(int i=0;i<n;i++){
        if(p[i] == i){
            ans = min(ans, cnt[i]);
        }
    }
    return ans;
}

Compilation message

insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:27:55: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   27 |             int l = 0, r = (int)u.size() - 1, mid = l + r >> 1;
      |                                                     ~~^~~
insects.cpp:36:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for(int i=0;i<u.size();i++){
      |                 ~^~~~~~~~~
insects.cpp:60:30: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   60 |                 int nmid = 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 0 ms 344 KB Output is correct
6 Correct 2 ms 452 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 4 ms 344 KB Output is correct
9 Correct 6 ms 464 KB Output is correct
10 Correct 3 ms 344 KB Output is correct
11 Correct 5 ms 344 KB Output is correct
12 Correct 3 ms 460 KB Output is correct
13 Correct 4 ms 600 KB Output is correct
14 Correct 4 ms 344 KB Output is correct
15 Correct 6 ms 344 KB Output is correct
16 Correct 6 ms 464 KB Output is correct
17 Correct 4 ms 344 KB Output is correct
18 Correct 5 ms 460 KB Output is correct
19 Correct 5 ms 344 KB Output is correct
20 Correct 5 ms 460 KB Output is correct
21 Correct 4 ms 600 KB Output is correct
22 Correct 4 ms 344 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 0 ms 344 KB Output is correct
6 Correct 2 ms 452 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 4 ms 344 KB Output is correct
9 Correct 6 ms 464 KB Output is correct
10 Correct 3 ms 344 KB Output is correct
11 Correct 5 ms 344 KB Output is correct
12 Correct 3 ms 460 KB Output is correct
13 Correct 4 ms 600 KB Output is correct
14 Correct 4 ms 344 KB Output is correct
15 Correct 6 ms 344 KB Output is correct
16 Correct 6 ms 464 KB Output is correct
17 Correct 4 ms 344 KB Output is correct
18 Correct 5 ms 460 KB Output is correct
19 Correct 5 ms 344 KB Output is correct
20 Correct 5 ms 460 KB Output is correct
21 Correct 4 ms 600 KB Output is correct
22 Correct 4 ms 344 KB Output is correct
23 Correct 7 ms 344 KB Output is correct
24 Correct 4 ms 344 KB Output is correct
25 Correct 38 ms 600 KB Output is correct
26 Correct 28 ms 592 KB Output is correct
27 Correct 10 ms 592 KB Output is correct
28 Correct 19 ms 600 KB Output is correct
29 Correct 25 ms 976 KB Output is correct
30 Correct 34 ms 616 KB Output is correct
31 Correct 17 ms 344 KB Output is correct
32 Correct 21 ms 344 KB Output is correct
33 Correct 34 ms 484 KB Output is correct
34 Correct 30 ms 620 KB Output is correct
35 Correct 26 ms 588 KB Output is correct
36 Correct 26 ms 740 KB Output is correct
37 Correct 27 ms 592 KB Output is correct
38 Correct 33 ms 620 KB Output is correct
39 Correct 40 ms 588 KB Output is correct
40 Correct 31 ms 612 KB Output is correct
41 Correct 16 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 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 17 ms 496 KB Output is correct
8 Correct 12 ms 456 KB Output is correct
9 Partially correct 76 ms 756 KB Output is partially correct
10 Partially correct 68 ms 592 KB Output is partially correct
11 Correct 16 ms 344 KB Output is correct
12 Partially correct 59 ms 344 KB Output is partially correct
13 Partially correct 40 ms 744 KB Output is partially correct
14 Partially correct 78 ms 344 KB Output is partially correct
15 Partially correct 41 ms 540 KB Output is partially correct
16 Partially correct 40 ms 540 KB Output is partially correct
17 Partially correct 51 ms 544 KB Output is partially correct
18 Partially correct 62 ms 480 KB Output is partially correct
19 Partially correct 74 ms 480 KB Output is partially correct
20 Partially correct 76 ms 600 KB Output is partially correct
21 Partially correct 72 ms 796 KB Output is partially correct
22 Partially correct 84 ms 792 KB Output is partially correct
23 Partially correct 92 ms 788 KB Output is partially correct
24 Partially correct 106 ms 536 KB Output is partially correct
25 Partially correct 64 ms 772 KB Output is partially correct
26 Partially correct 62 ms 728 KB Output is partially correct
27 Partially correct 82 ms 768 KB Output is partially correct
28 Partially correct 68 ms 592 KB Output is partially correct
29 Partially correct 65 ms 592 KB Output is partially correct
30 Partially correct 60 ms 344 KB Output is partially correct
31 Partially correct 61 ms 660 KB Output is partially correct
32 Partially correct 75 ms 544 KB Output is partially correct
33 Partially correct 103 ms 1256 KB Output is partially correct
34 Partially correct 71 ms 544 KB Output is partially correct
35 Partially correct 106 ms 544 KB Output is partially correct
36 Partially correct 79 ms 776 KB Output is partially correct
37 Partially correct 82 ms 736 KB Output is partially correct
38 Partially correct 73 ms 592 KB Output is partially correct
39 Partially correct 98 ms 768 KB Output is partially correct
40 Partially correct 99 ms 588 KB Output is partially correct
41 Partially correct 78 ms 760 KB Output is partially correct
42 Partially correct 75 ms 592 KB Output is partially correct
43 Partially correct 10 ms 600 KB Output is partially correct
44 Partially correct 28 ms 544 KB Output is partially correct
45 Correct 25 ms 344 KB Output is correct
46 Correct 17 ms 464 KB Output is correct
47 Partially correct 70 ms 916 KB Output is partially correct
48 Partially correct 35 ms 468 KB Output is partially correct