# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
830495 | josanneo22 | 드문 곤충 (IOI22_insects) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ld long double
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
vector<int> a;
int tot,cnt,n;
void add(int x){tot++; move_inside(x);}
void del(int x){tot--; move_outside(x);}
int ask(){ return press_button();}
/* a[i]=-2 temp added, a[i]=-1 temp over, a[i]=0 over, a[i]=1 first meet, a[i]=2 repeat*/
bool check(int x){
int sz=cnt;
for(int i=0;i<n;i++){
if(a[i]==1 || a[i]==0) continue;
add(i); sz++; a[i]=-2;
if(ask()>x){del(i); a[i]=-1;sz--;}
}
if(cnt*x==sz){//答案可以接受需要rollback所有操作
for(int i=0;i<n;i++){
if(a[i]==-2){ del(i); a[i]=2;}
if(a[i]==-1){ a[i]=2;}
}
return true;
}
else{
for(int i=0;i<n;i++){
if(a[i]==-2){ del(i); a[i]=2;}
if(a[i]==-1) a[i]=0;
}
return false;
}
}
int min_cardinality(int N) {
n=N;
a.assign(n,2);
for(int i=0;i<n;i++){ add(i); if(ask()>1) del(i); else a[i]=1,cnt++;}
int l=1,r=n/cnt,res=n+1;
while(l<r){
int mid=(l+r)>>1;
if(check(mid)){ res=mid; l=mid+1;}
else r=mid-1;
}
return res;
}