제출 #964847

#제출 시각아이디문제언어결과실행 시간메모리
964847steveonalex드문 곤충 (IOI22_insects)C++17
47.50 / 100
117 ms1344 KiB
#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;
// }

컴파일 시 표준 에러 (stderr) 메시지

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...