Submission #643669

#TimeUsernameProblemLanguageResultExecution timeMemory
643669VanillaRarest Insects (IOI22_insects)C++17
53.90 / 100
167 ms336 KiB
#include <bits/stdc++.h> #include "insects.h" using namespace std; int min_cardinality(int n) { unsigned seed = std::chrono::system_clock::now().time_since_epoch().count(); std::default_random_engine rng(seed); vector <bool> tr (n); int tp = 0; for (int i = 0; i < n; i++){ move_inside(i); if (press_button() == 2) { move_outside(i); } else { tr[i] = 1; tp++; } } for (int i = 0; i < n; i++) if (tr[i]) move_outside(i); int l = 0, r = n / tp, rs = -1; int btn = 0; vector <int> in (n); while (l <= r){ int mid = (l + r) / 2; auto check = [&] (int x) -> bool { int ins = btn; vector <int> vis (n); vector <int> ord (n); iota(ord.begin(), ord.end(), 0); shuffle(ord.begin(), ord.end(), rng); for (int i: ord) { if (in[i]) continue; move_inside(i); if (press_button() > x) { move_outside(i); } else { ins++; vis[i] = in[i] = 1; } if (ins == x * tp) { btn = ins; return 1; } } if (ins != x * tp) { for (int i = 0; i < n; i++) if (vis[i]) { in[i] = 0; move_outside(i); } return 0; } else { btn = ins; return 1; } }; if (check(mid)) { rs = mid; l = mid + 1; } else { r = mid - 1; } } return rs; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...