Submission #641181

#TimeUsernameProblemLanguageResultExecution timeMemory
641181TimDeeRarest Insects (IOI22_insects)C++17
82.18 / 100
100 ms332 KiB
#include "insects.h" #include <bits/stdc++.h> using namespace std; int n; int min_cardinality(int N) { n=N; int d=0; vector<int> in(n,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; } } if (d==1) return n; if (d>n/2) return 1; if (d<=8) { for (int i=0; i<n; ++i) { if (in[i]) { in[i]=0; move_outside(i); } } int ans=n; vector<int> vis(n,0); for (int i=0; i<d; ++i) { vector<int> bulaneala; int cnt=0; 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; } 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) { if (extra==0) { return mid; } else { l=mid; now=cnt; } laststate=in; } else { now=0; r=mid-1; for (int i=0; i<n; ++i) { if ((in[i])&&(laststate[i]==0)) move_outside(i); in[i]=0; } } } return r; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...