Submission #1074647

#TimeUsernameProblemLanguageResultExecution timeMemory
1074647NicolaikrobRarest Insects (IOI22_insects)C++17
99.89 / 100
55 ms1212 KiB
#include "insects.h" #include <bits/stdc++.h> using namespace std; typedef vector<int> vi; int n, tc, il, rc = 0; set<int> M, IU; vi IS; void mi(int i) { move_inside(IS[i]); M.insert(i); } void mo(int i) { move_outside(IS[i]); M.erase(i); } int pb() { return press_button()+rc; } void rm(bool t) { if(t) { for(auto x : M) { IU.erase(x); move_outside(IS[x]); } il -= M.size(); rc += M.size()/tc; M.clear(); } else { IU = M; il = M.size(); for(auto x : M) move_outside(IS[x]); M.clear(); } } bool tjek(int g) { for(auto i : IU) { mi(i); if(pb() > g) mo(i); } bool s = (int(M.size())+rc*tc == tc*g); rm(s); return s; } int min_cardinality(int N) { il = n = N; IS.resize(n); for(int i = 0; i < n; i++) IS[i] = i; srand(time(NULL)); random_shuffle(IS.begin(), IS.end()); mi(0); for(int i = 1; i < n; i++) { mi(i); if(pb() > 1) mo(i); } tc = M.size(); for(int i = 0; i < n; i++) IU.insert(i); rm(1); int l = 1, u = n/tc; while(l < u) { int mx = 0, g = (l+u+1)/2; for(int i = l+1; i <= u; i++) { int t = min(tc*(i-rc), il-tc*(i-rc)+1); if(t > mx) mx = t, g = i; } if(tjek(g)) l = g; else u = g-1; } return l; } /* 12 3 3 3 4 4 4 4 5 5 5 5 4 11 1 3 3 7 1 3 5 7 5 1 3 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...