답안 #964858

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
964858 2024-04-17T16:41:40 Z steveonalex 드문 곤충 (IOI22_insects) C++17
99.89 / 100
39 ms 1392 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){
            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 (press_button() > 1) {
                move_outside(i);
                S.pop_back();
            }
        }

        int d_cnt = S.size();
        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);
        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:87:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   87 |         if (S.size() == d_cnt * mid){
      |             ~~~~~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 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 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 2 ms 344 KB Output is correct
11 Correct 1 ms 436 KB Output is correct
12 Correct 2 ms 600 KB Output is correct
13 Correct 2 ms 600 KB Output is correct
14 Correct 2 ms 600 KB Output is correct
15 Correct 2 ms 344 KB Output is correct
16 Correct 2 ms 600 KB Output is correct
17 Correct 3 ms 600 KB Output is correct
18 Correct 3 ms 600 KB Output is correct
19 Correct 4 ms 596 KB Output is correct
20 Correct 2 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 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 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 2 ms 344 KB Output is correct
11 Correct 1 ms 436 KB Output is correct
12 Correct 2 ms 600 KB Output is correct
13 Correct 2 ms 600 KB Output is correct
14 Correct 2 ms 600 KB Output is correct
15 Correct 2 ms 344 KB Output is correct
16 Correct 2 ms 600 KB Output is correct
17 Correct 3 ms 600 KB Output is correct
18 Correct 3 ms 600 KB Output is correct
19 Correct 4 ms 596 KB Output is correct
20 Correct 2 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 600 KB Output is correct
23 Correct 4 ms 344 KB Output is correct
24 Correct 5 ms 448 KB Output is correct
25 Correct 12 ms 848 KB Output is correct
26 Correct 19 ms 600 KB Output is correct
27 Correct 15 ms 704 KB Output is correct
28 Correct 5 ms 604 KB Output is correct
29 Correct 11 ms 600 KB Output is correct
30 Correct 15 ms 696 KB Output is correct
31 Correct 18 ms 616 KB Output is correct
32 Correct 14 ms 944 KB Output is correct
33 Correct 13 ms 692 KB Output is correct
34 Correct 13 ms 856 KB Output is correct
35 Correct 18 ms 936 KB Output is correct
36 Correct 18 ms 868 KB Output is correct
37 Correct 13 ms 856 KB Output is correct
38 Correct 12 ms 700 KB Output is correct
39 Correct 10 ms 1112 KB Output is correct
40 Correct 7 ms 604 KB Output is correct
41 Correct 6 ms 600 KB Output is correct
# 결과 실행 시간 메모리 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 1 ms 344 KB Output is correct
7 Correct 12 ms 344 KB Output is correct
8 Correct 12 ms 600 KB Output is correct
9 Correct 32 ms 948 KB Output is correct
10 Correct 28 ms 1392 KB Output is correct
11 Correct 26 ms 1128 KB Output is correct
12 Correct 16 ms 848 KB Output is correct
13 Correct 35 ms 672 KB Output is correct
14 Correct 32 ms 956 KB Output is correct
15 Correct 25 ms 880 KB Output is correct
16 Correct 39 ms 420 KB Output is correct
17 Correct 28 ms 712 KB Output is correct
18 Correct 32 ms 456 KB Output is correct
19 Partially correct 32 ms 460 KB Output is partially correct
20 Correct 29 ms 700 KB Output is correct
21 Correct 29 ms 672 KB Output is correct
22 Correct 30 ms 700 KB Output is correct
23 Correct 23 ms 456 KB Output is correct
24 Correct 26 ms 696 KB Output is correct
25 Correct 17 ms 676 KB Output is correct
26 Correct 10 ms 600 KB Output is correct
27 Correct 28 ms 460 KB Output is correct
28 Correct 28 ms 460 KB Output is correct
29 Partially correct 30 ms 688 KB Output is partially correct
30 Partially correct 24 ms 696 KB Output is partially correct
31 Correct 29 ms 700 KB Output is correct
32 Correct 28 ms 724 KB Output is correct
33 Correct 30 ms 708 KB Output is correct
34 Correct 25 ms 692 KB Output is correct
35 Partially correct 26 ms 440 KB Output is partially correct
36 Partially correct 32 ms 700 KB Output is partially correct
37 Correct 29 ms 712 KB Output is correct
38 Correct 32 ms 672 KB Output is correct
39 Correct 31 ms 672 KB Output is correct
40 Correct 27 ms 700 KB Output is correct
41 Partially correct 29 ms 712 KB Output is partially correct
42 Partially correct 29 ms 924 KB Output is partially correct
43 Correct 6 ms 600 KB Output is correct
44 Correct 26 ms 856 KB Output is correct
45 Correct 26 ms 708 KB Output is correct
46 Correct 13 ms 708 KB Output is correct
47 Correct 14 ms 680 KB Output is correct
48 Correct 13 ms 708 KB Output is correct