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 "insects.h"
#include <bits/stdc++.h>
using namespace std;
int n,d;
vector<int> in(2005,0);
vector<int> uniq;
int f(int l, int r, vector<int> from) {
//cout<<l<<' '<<r<<'\n';
//for (auto x:from) cout<<x<<' '; cout<<'\n';
if (r-l==0) {
move_outside(uniq[r]);
return from.size()+1;
}
int mid=(l+r+1)>>1;
vector<int> left, right;
for (int i=mid; i<=r; ++i) move_outside(uniq[i]);
for (auto x:from) {
move_inside(x);
int k=press_button();
if (k>1) left.push_back(x);
else right.push_back(x);
move_outside(x);
}
int L=f(l,mid-1,left);
//for (int i=0; i<mid; ++i) move_outside(uniq[i]);
for (int i=mid; i<=r; ++i) move_inside(uniq[i]);
int R=f(mid,r,right);
return min(L,R);
}
int min_cardinality(int N) {
n=N;
d=0;
for(int i=0; i<n; ++i) {
move_inside(i);
int x=press_button();
if (x>1) move_outside(i);
else { in[i]=1; ++d; }
}
for (int i=0; i<n; ++i) if (in[i]) uniq.push_back(i);
if (d==1) return n;
if (d>n/2) return 1;
if (d<=2) {
int ans=n;
vector<int> vis(n,0);
for (int i=0; i<n; ++i) vis[i]=in[i];
for (int i=0; i<d; ++i) {
vector<int> bulaneala;
int cnt=1;
for (int i=0; i<n; ++i) {
if (vis[i]) continue;
move_inside(i);
int x=press_button();
if (x==cnt) move_outside(i);
else {
bulaneala.push_back(i);
++cnt;
vis[i]=1;
}
}
ans=min(ans,cnt);
for (auto x:bulaneala) move_outside(x);
}
return ans;
}
if (d<=8) {
int l=0, r=d-1;
vector<int> scuza;
for (int i=0; i<n; ++i) if (!in[i]) scuza.push_back(i);
return f(l,r,scuza);
}
int l=1, r=n/d;
int now=d;
vector<int> laststate=in;
while (l<r) {
int mid=(l+r+1)>>1;
int extra=0;
int cnt=now;
for (int i=0; i<n; ++i) {
if (in[i]) continue;
in[i]=1;
move_inside(i);
int x=press_button();
if (x>mid) {
extra=1;
move_outside(i);
in[i]=0;
} else ++cnt;
if (cnt==mid*d) break;
}
if (cnt==mid*d) {
if (extra==0) {
return mid;
} else {
l=mid;
now=cnt;
}
laststate=in;
} else {
now=cnt;
r=mid-1;
for (int i=0; i<n; ++i) { if ((in[i])&&(laststate[i]==0)) {move_outside(i); --now;} in[i]=laststate[i]; }
}
}
return r;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |