Submission #1005516

# Submission time Handle Problem Language Result Execution time Memory
1005516 2024-06-22T14:30:51 Z khanhtb Rarest Insects (IOI22_insects) C++17
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
#include "insects.h"
#define ll int
#define ull unsigned long long
#define ld double
#define pb push_back
#define pf push_front
#define vi vector<ll>
#define vii vector<vi>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define all(a) a.begin(), a.end()
#define fi first
#define se second
using namespace std;
const ll mod = 1e9+7;
const ll inf = 1e18;
const ll base = 31;
const ll blocksz = 320;
const ll N = 1e5+8;
set<int> in_machine;
map<int,set<int>> max_k;
vector<int> reset;
int n,d,p[N];
void add(ll i){
    move_inside(p[i]);
    in_machine.insert(i);
}
void del(ll i){
    move_outside(p[i]);
    in_machine.erase(in_machine.find(i));
}
bool check(int m){
    reset.clear();
    auto mk = *max_k.lower_bound(m);
    for(int p:mk.se){
        if(in_machine.find(p) != in_machine.end()) continue;
        if((int)in_machine.size() >= d*m) return 1;
        add(p);
        if(press_button() > m) del(p);
        else reset.pb(p);
    }
    max_k[m] = in_machine;
    if((int)in_machine.size() >= d*m) return 1;
    return 0;
}
int min_cardinality(int n){
    iota(p+1,p+n+1,0LL);
    shuffle(p+1,p+n+1,default_random_engine(1));
    for(int i = 0; i < n; i++){
        add(i);
        if(press_button() > 1) del(i);
    }
    d = (int)in_machine.size();
    max_k[1] = in_machine;
    for(int i = 0; i < n; i++) max_k[n].insert(i);
    int ans = 1;
    int l = 2, r = n/d;
    while(l <= r){
        int m = l+r>>1;
        if(check(m)){
            ans = m;
            l = m+1;
        }
        else{
            r = m-1;
            for(int i:reset) del(i);
        }
    }
    return ans;
}
signed main(){
    cin >> n;
    cout << min_cardinality(n);
}

Compilation message

insects.cpp:17:16: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   17 | const ll inf = 1e18;
      |                ^~~~
insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:60:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   60 |         int m = l+r>>1;
      |                 ~^~
/usr/bin/ld: /tmp/cclcYHQM.o: in function `main':
stub.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccA2Dh6J.o:insects.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status