제출 #1369361

#제출 시각아이디문제언어결과실행 시간메모리
1369361huangallen드문 곤충 (IOI22_insects)C++20
99.89 / 100
12 ms516 KiB
#include "insects.h"
#ifdef LOCAL
#include "stub.cpp"
#endif
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define iint signed 
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP1(i,n) for(int i=1;i<=(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define RREP1(i,n) for(int i=(n);i>=1;i--)
#define f first
#define s second
#define pb push_back
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)((x).size()))
#define pii pair<int,int>
#define Graph vector<vector<int>>
#define Graphw vector<vector<pii>>
template<typename S> void chmin(S &x,S y) { x=min(x,y); }
template<typename S> void chmax(S &x,S y) { x=max(x,y); }
#define Vi vector<int>
#define Vpii vector<pii>
#ifdef LOCAL
#define op(x) cout<<(#x)<<"="<<(x)<<", ";
#define ope(x) cout<<(#x)<<"="<<(x)<<endl;
#define oparr(x) {cout<<(#x)<<":";for(auto allen:(x)) cout<<allen<<" ";cout<<" size="<<(x).size()<<endl;}
#define entr cout<<endl;
#else
#define op(x) ;
#define ope(x) ;
#define oparr(x) ;
#define entr ;
#endif
template<typename S>
ostream& operator<<(ostream& os,vector<S> p) { for(auto allen:p) os<<allen<<' ';return os<<'\n'; }
template<typename S>
istream& operator>>(istream& os,vector<S> &p) { for(auto &allen:p) os>>allen;return os; }
multiset<int> box;
void movein(int i) { op("in")ope(i)box.insert(i);move_inside(i); }
void moveout(int i) { op("ou")ope(i)box.erase(box.find(i));move_outside(i); }
int press() { return press_button(); }
iint min_cardinality(iint N) {
    int n=N;
    Vi a,b;
    movein(0);
    a.pb(0);
    REP1(i,n-1) {
        movein(i);
        if(press()==2) {
            moveout(i);
            b.pb(i);
        }else {
            a.pb(i);
        }
    }
    int m=SZ(a),k=SZ(b);
    int l=1,r=n/m,mid;
    Vi inb(n);
    int cnt=0;
    Vi no(n);
    for(int x:a) inb[x]=1,cnt++,no[x]=1;
    oparr(a)oparr(b)
    while(l<r) {
        mid=l+r+1>>1;
        Vi t;
        REP(i,n) if(!no[i]) {
            movein(i);
            inb[i]=1;
            cnt++;
            t.pb(i);
            if(press()>mid) moveout(i),cnt--,inb[i]=0,t.pop_back();
        }
        op(l)op(r)ope(mid)
        if(cnt==m*mid) {
            REP(i,n) if(inb[i]) no[i]=1;
            l=mid;
            // ope("!")
        }else {
            REP(i,n) if(!inb[i]) no[i]=1;
            for(int x:t) {
                moveout(x),cnt--,inb[x]=0;
            }
            r=mid-1;
        }
    }
    return l;
}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…