Submission #641459

#TimeUsernameProblemLanguageResultExecution timeMemory
641459TimDeeRarest Insects (IOI22_insects)C++17
99.89 / 100
66 ms332 KiB
#include "insects.h" #include <bits/stdc++.h> using namespace std; int n,d; vector<int> in(2005,0); vector<int> uniq; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int min_cardinality(int N) { n=N; d=0; vector<int> use; for (int i=0; i<n; ++i) { use.push_back(i); } shuffle(use.begin(), use.end(),rng); for(int i=0; i<n; ++i) { move_inside(use[i]); int x=press_button(); if (x>1) move_outside(use[i]); else { in[use[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) { for (auto x:uniq) move_outside(x); int cnt=0; for (auto x:use) { move_inside(x); int X=press_button(); if (X==cnt+1) ++cnt; else move_outside(x); } return min(cnt,n-cnt); } if (d==3) { int cnt=1; vector<int> paiu; for (auto x:use) { if (in[x]) continue; move_inside(x); int X=press_button(); if (X==cnt+1) {++cnt; paiu.push_back(x); in[x]=1;} else move_outside(x); } int ans=cnt; for (auto x:paiu) move_outside(x); cnt=1; for (auto x:use) { if (in[x]) continue; move_inside(x); int X=press_button(); if (X==cnt+1) {++cnt; paiu.push_back(x); in[x]=1;} else move_outside(x); } ans=min({ans,cnt,n-cnt-ans}); return ans; } int l=1, r=n/d; int now=d; while (l<r) { vector<int> add; int mid=(l+r+1)>>1; int extra=0; int cnt=now; shuffle(use.begin(), use.end(),rng); for (auto x:use) { if (in[x]) continue; in[x]=1; move_inside(x); int X=press_button(); if (X>mid) { extra=1; move_outside(x); in[x]=0; } else { ++cnt; add.push_back(x); } //if (cnt==mid*d) break; } if (cnt==mid*d) { if (extra==0) { return mid; } else { l=mid; now=cnt; } } else { now=cnt; r=mid-1; use=add; for (auto x:add) { --now; in[x]=0; move_outside(x); } } } return r; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...