Submission #964870

# Submission time Handle Problem Language Result Execution time Memory
964870 2024-04-17T16:48:43 Z steveonalex Rarest Insects (IOI22_insects) C++17
100 / 100
33 ms 1212 KB
#include <bits/stdc++.h>
#include "insects.h"

using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define ALL(v) (v).begin(), (v).end()
#define MASK(i) (1LL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
 
// mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng(1);
ll rngesus(ll l, ll r){return ((ull) rng()) % (r - l + 1) + l;}
 
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
 
ll LASTBIT(ll mask){return mask & (-mask);}
ll pop_cnt(ll mask){return __builtin_popcountll(mask);}
ll ctz(ll mask){return __builtin_ctzll(mask);}
ll clz(ll mask){return __builtin_clzll(mask);}
ll logOf(ll mask){return 63 - clz(mask);}
 
template <class T1, class T2>
    bool minimize(T1 &a, T2 b){
        if (a > b){a = b; return true;}
        return false;
    }
template <class T1, class T2>
    bool maximize(T1 &a, T2 b){
        if (a < b){a = b; return true;}
        return false;
    }
template <class T>
    void printArr(T& a, string separator = " ", string finish = "\n", ostream& out = cout){
        for(auto i: a) out << i << separator;
        out << finish;
    }
template <class T>
    void remove_dup(vector<T> &a){
        sort(ALL(a));
        a.resize(unique(ALL(a)) - a.begin());
    }

// namespace Grader{
//     int n;
//     vector<int> a;
//     set<int> S;
//     int o_cnt[3];

//     void move_inside(int i){
//         o_cnt[0]++;
//         S.insert(i);
//     }

//     void move_outside(int i){
//         o_cnt[1]++;
//         S.erase(i);
//     }

//     int press_button(){
//         o_cnt[2]++;
//         map<int, int> mp;
//         int ans = 0;
//         for(int i: S) {
//             maximize(ans, ++mp[a[i]]);
//         }
//         return ans;
//     }

    int BS(int l, int r, int d_cnt, vector<int> &S, vector<int> space){
        if (l == r) return l;
        int mid = (l + r + 1) >> 1;
        vector<int> left, right;
        for(int i: space){
            if (S.size() == d_cnt * mid) {
                right.push_back(i);
                continue;
            } 
            move_inside(i);
            S.push_back(i);
            if (press_button() > mid) {
                move_outside(i);
                right.push_back(i);
                S.pop_back();
            }
            else left.push_back(i);
        }
        if (S.size() == d_cnt * mid){
            return BS(mid, r, d_cnt, S, right);
        }
        else{
            for(int i: left) {
                move_outside(i);
                S.pop_back();
            }
            return BS(l, mid - 1, d_cnt, S, left);
        }

        return 0;
    }

    int min_cardinality(int n){
        //find number of distinct dud
        vector<int> S;
        for(int i = 0; i<n; ++i){
            move_inside(i);
            S.push_back(i);
            if (i > 0 && press_button() > 1) {
                move_outside(i);
                S.pop_back();
            }
        }

        int d_cnt = S.size();
        sort(ALL(S));
        if (d_cnt == 1) return n;

        vector<int> space;
        for(int i= 0; i<n; ++i) if (!binary_search(ALL(S), i)) space.push_back(i);
        shuffle(ALL(space), rng);
        return BS(1, n / d_cnt, d_cnt, S, space);
    }

//     pair<bool, int> solve(int _n){
//         n = _n;
//         a.resize(n);
//         S.clear();
//         memset(o_cnt, 0, sizeof o_cnt);
//         for(int i = 0; i<n; ++i) a[i] = rngesus(1, 10);

//         int ans = min_cardinality(n);
//         map<int, int> mp;
//         for(int i: a) mp[i]++;
//         int mi = 1e9;
//         for(auto i: mp) minimize(mi, i.second);

//         return make_pair(mi == ans, max({o_cnt[0], o_cnt[1], o_cnt[2]}));
//     }
// }

// int main(void){
//     ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

//     int n = 2000;
//     pair<bool, int> verdict = Grader::solve(n);
//     if (verdict.first) cout << "AC\n";
//     else cout << "WA\n";

//     cout << "Operation cnt: " << verdict.second << "\n";

//     return 0;
// }

Compilation message

insects.cpp: In function 'int BS(int, int, int, std::vector<int>&, std::vector<int>)':
insects.cpp:78:26: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   78 |             if (S.size() == d_cnt * mid) {
      |                 ~~~~~~~~~^~~~~~~~~~~~~~
insects.cpp:91:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   91 |         if (S.size() == d_cnt * mid){
      |             ~~~~~~~~~^~~~~~~~~~~~~~
# 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 1 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 1 ms 344 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Correct 3 ms 600 KB Output is correct
10 Correct 2 ms 600 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 2 ms 600 KB Output is correct
13 Correct 2 ms 344 KB Output is correct
14 Correct 3 ms 692 KB Output is correct
15 Correct 2 ms 600 KB Output is correct
16 Correct 3 ms 600 KB Output is correct
17 Correct 2 ms 600 KB Output is correct
18 Correct 2 ms 344 KB Output is correct
19 Correct 2 ms 604 KB Output is correct
20 Correct 3 ms 600 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 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 1 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 1 ms 344 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Correct 3 ms 600 KB Output is correct
10 Correct 2 ms 600 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 2 ms 600 KB Output is correct
13 Correct 2 ms 344 KB Output is correct
14 Correct 3 ms 692 KB Output is correct
15 Correct 2 ms 600 KB Output is correct
16 Correct 3 ms 600 KB Output is correct
17 Correct 2 ms 600 KB Output is correct
18 Correct 2 ms 344 KB Output is correct
19 Correct 2 ms 604 KB Output is correct
20 Correct 3 ms 600 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 6 ms 344 KB Output is correct
24 Correct 4 ms 600 KB Output is correct
25 Correct 13 ms 696 KB Output is correct
26 Correct 13 ms 696 KB Output is correct
27 Correct 10 ms 692 KB Output is correct
28 Correct 5 ms 600 KB Output is correct
29 Correct 11 ms 872 KB Output is correct
30 Correct 12 ms 696 KB Output is correct
31 Correct 8 ms 436 KB Output is correct
32 Correct 10 ms 856 KB Output is correct
33 Correct 11 ms 848 KB Output is correct
34 Correct 11 ms 616 KB Output is correct
35 Correct 10 ms 692 KB Output is correct
36 Correct 11 ms 856 KB Output is correct
37 Correct 14 ms 856 KB Output is correct
38 Correct 12 ms 848 KB Output is correct
39 Correct 9 ms 852 KB Output is correct
40 Correct 7 ms 600 KB Output is correct
41 Correct 4 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 596 KB Output is correct
4 Correct 0 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 9 ms 344 KB Output is correct
8 Correct 9 ms 600 KB Output is correct
9 Correct 23 ms 720 KB Output is correct
10 Correct 33 ms 708 KB Output is correct
11 Correct 21 ms 620 KB Output is correct
12 Correct 14 ms 600 KB Output is correct
13 Correct 21 ms 924 KB Output is correct
14 Correct 26 ms 956 KB Output is correct
15 Correct 20 ms 448 KB Output is correct
16 Correct 22 ms 448 KB Output is correct
17 Correct 29 ms 700 KB Output is correct
18 Correct 24 ms 592 KB Output is correct
19 Correct 21 ms 852 KB Output is correct
20 Correct 27 ms 616 KB Output is correct
21 Correct 30 ms 696 KB Output is correct
22 Correct 32 ms 664 KB Output is correct
23 Correct 25 ms 952 KB Output is correct
24 Correct 22 ms 960 KB Output is correct
25 Correct 15 ms 600 KB Output is correct
26 Correct 10 ms 860 KB Output is correct
27 Correct 21 ms 1112 KB Output is correct
28 Correct 24 ms 592 KB Output is correct
29 Correct 24 ms 704 KB Output is correct
30 Correct 23 ms 1212 KB Output is correct
31 Correct 24 ms 1128 KB Output is correct
32 Correct 30 ms 880 KB Output is correct
33 Correct 29 ms 928 KB Output is correct
34 Correct 30 ms 1180 KB Output is correct
35 Correct 21 ms 712 KB Output is correct
36 Correct 23 ms 856 KB Output is correct
37 Correct 28 ms 460 KB Output is correct
38 Correct 27 ms 936 KB Output is correct
39 Correct 28 ms 604 KB Output is correct
40 Correct 22 ms 632 KB Output is correct
41 Correct 25 ms 848 KB Output is correct
42 Correct 24 ms 704 KB Output is correct
43 Correct 6 ms 600 KB Output is correct
44 Correct 16 ms 624 KB Output is correct
45 Correct 21 ms 592 KB Output is correct
46 Correct 12 ms 852 KB Output is correct
47 Correct 12 ms 600 KB Output is correct
48 Correct 15 ms 936 KB Output is correct