Submission #964847

# Submission time Handle Problem Language Result Execution time Memory
964847 2024-04-17T16:20:11 Z steveonalex Rarest Insects (IOI22_insects) C++17
47.5 / 100
117 ms 1344 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 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 (press_button() > 1) {
                move_outside(i);
                S.pop_back();
            }
        }

        int d_cnt = S.size();
        while(S.size()){
            move_outside(S.back());
            S.pop_back();
        }

        int l = 1, r = n / d_cnt;
        while(l < r){
            int mid = (l + r + 1) >> 1;
            vector<int> S;
            for(int i = 0; i<n; ++i){
                S.push_back(i);
                move_inside(i);
                if (press_button() > mid) {
                    move_outside(i);
                    S.pop_back();
                }
            }
            if (S.size() < d_cnt * mid) r = mid - 1;
            else l = mid;

            while(S.size()){
                move_outside(S.back());
                S.pop_back();
            }
        }
        return l;
    }

//     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 min_cardinality(int)':
insects.cpp:103:26: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  103 |             if (S.size() < d_cnt * mid) r = mid - 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 1 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 7 ms 444 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 4 ms 600 KB Output is correct
9 Correct 4 ms 348 KB Output is correct
10 Correct 6 ms 352 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 5 ms 600 KB Output is correct
13 Correct 4 ms 344 KB Output is correct
14 Correct 6 ms 600 KB Output is correct
15 Correct 5 ms 600 KB Output is correct
16 Correct 5 ms 600 KB Output is correct
17 Correct 4 ms 344 KB Output is correct
18 Correct 4 ms 344 KB Output is correct
19 Correct 4 ms 604 KB Output is correct
20 Correct 2 ms 600 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 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 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 7 ms 444 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 4 ms 600 KB Output is correct
9 Correct 4 ms 348 KB Output is correct
10 Correct 6 ms 352 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 5 ms 600 KB Output is correct
13 Correct 4 ms 344 KB Output is correct
14 Correct 6 ms 600 KB Output is correct
15 Correct 5 ms 600 KB Output is correct
16 Correct 5 ms 600 KB Output is correct
17 Correct 4 ms 344 KB Output is correct
18 Correct 4 ms 344 KB Output is correct
19 Correct 4 ms 604 KB Output is correct
20 Correct 2 ms 600 KB Output is correct
21 Correct 2 ms 344 KB Output is correct
22 Correct 1 ms 600 KB Output is correct
23 Correct 45 ms 1184 KB Output is correct
24 Correct 4 ms 856 KB Output is correct
25 Correct 25 ms 1176 KB Output is correct
26 Correct 27 ms 1112 KB Output is correct
27 Correct 45 ms 600 KB Output is correct
28 Correct 4 ms 344 KB Output is correct
29 Correct 37 ms 600 KB Output is correct
30 Correct 26 ms 440 KB Output is correct
31 Correct 42 ms 924 KB Output is correct
32 Correct 34 ms 924 KB Output is correct
33 Correct 36 ms 928 KB Output is correct
34 Correct 37 ms 1100 KB Output is correct
35 Correct 31 ms 1104 KB Output is correct
36 Correct 29 ms 1196 KB Output is correct
37 Correct 25 ms 436 KB Output is correct
38 Correct 19 ms 416 KB Output is correct
39 Correct 13 ms 600 KB Output is correct
40 Correct 7 ms 600 KB Output is correct
41 Correct 4 ms 608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 596 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Partially correct 0 ms 344 KB Output is partially correct
7 Partially correct 117 ms 928 KB Output is partially correct
8 Correct 10 ms 600 KB Output is correct
9 Partially correct 60 ms 688 KB Output is partially correct
10 Partially correct 51 ms 932 KB Output is partially correct
11 Partially correct 110 ms 344 KB Output is partially correct
12 Correct 19 ms 852 KB Output is correct
13 Partially correct 91 ms 696 KB Output is partially correct
14 Partially correct 62 ms 596 KB Output is partially correct
15 Partially correct 88 ms 912 KB Output is partially correct
16 Partially correct 92 ms 1332 KB Output is partially correct
17 Partially correct 92 ms 680 KB Output is partially correct
18 Partially correct 78 ms 852 KB Output is partially correct
19 Partially correct 94 ms 1344 KB Output is partially correct
20 Partially correct 69 ms 1168 KB Output is partially correct
21 Partially correct 59 ms 676 KB Output is partially correct
22 Partially correct 67 ms 932 KB Output is partially correct
23 Partially correct 37 ms 692 KB Output is partially correct
24 Correct 24 ms 948 KB Output is correct
25 Correct 20 ms 680 KB Output is correct
26 Correct 11 ms 700 KB Output is correct
27 Partially correct 56 ms 936 KB Output is partially correct
28 Partially correct 52 ms 920 KB Output is partially correct
29 Partially correct 81 ms 680 KB Output is partially correct
30 Partially correct 78 ms 916 KB Output is partially correct
31 Partially correct 54 ms 692 KB Output is partially correct
32 Partially correct 70 ms 936 KB Output is partially correct
33 Partially correct 52 ms 852 KB Output is partially correct
34 Partially correct 60 ms 684 KB Output is partially correct
35 Partially correct 67 ms 688 KB Output is partially correct
36 Partially correct 60 ms 928 KB Output is partially correct
37 Partially correct 65 ms 676 KB Output is partially correct
38 Partially correct 54 ms 928 KB Output is partially correct
39 Partially correct 52 ms 684 KB Output is partially correct
40 Partially correct 44 ms 920 KB Output is partially correct
41 Partially correct 67 ms 852 KB Output is partially correct
42 Partially correct 66 ms 688 KB Output is partially correct
43 Partially correct 18 ms 440 KB Output is partially correct
44 Partially correct 79 ms 596 KB Output is partially correct
45 Partially correct 98 ms 1144 KB Output is partially correct
46 Correct 16 ms 440 KB Output is correct
47 Correct 23 ms 852 KB Output is correct
48 Correct 19 ms 856 KB Output is correct