Submission #627940

#TimeUsernameProblemLanguageResultExecution timeMemory
627940lunchboxRarest Insects (IOI22_insects)C++17
99.89 / 100
95 ms340 KiB
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); typedef vector<int> vi; #ifdef LOCAL void move_inside(int i); void move_outside(int i); int press_button(); #else #include "insects.h" #endif int min_cardinality(int n) { int c = 0; vi u, v, in(n), p(n); iota(p.begin(), p.end(), 0); for (int i = 0; i < n; i++) { move_inside(p[i]); if (press_button() == 1) { c++; in[i] = 1; } else { move_outside(p[i]); u.push_back(i); } } int low = 2, hi = n / c, sz = 0, ans = 1; while (low <= hi) { int t = (low + hi) / 2; v.clear(); shuffle(u.begin(), u.end(), rng); for (int i : u) { if (in[i]) continue; move_inside(p[i]); if (press_button() > t) { move_outside(p[i]); v.push_back(i); } else sz++; } if (c + sz == t * c) { fill(in.begin(), in.end(), 1); for (int i : v) in[i] = 0; ans = t; low = t + 1; } else { hi = t - 1; if (low <= hi) { for (int i : v) in[i] = 1; for (int i : u) if (!in[i]) { move_outside(p[i]); sz--; } } } } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...