Submission #1076850

#TimeUsernameProblemLanguageResultExecution timeMemory
1076850ZicrusRarest Insects (IOI22_insects)C++17
54.04 / 100
164 ms1252 KiB
#include <bits/stdc++.h> #include "insects.h" using namespace std; typedef long long ll; int n; vector<bool> in; unordered_set<int> sIn, sOut; int cnt; int numA, numP; mt19937 mt; void add(int i) { if (in[i]) return; numA++; move_inside(i); cnt++; in[i] = true; } int add_rand() { int id = mt() % sOut.size(); auto iter = sOut.begin(); while (id--) iter++; int i = *iter; add(i); sOut.erase(i); return i; } void remove(int i) { if (!in[i]) return; move_outside(i); cnt--; in[i] = false; } int remove_rand() { int id = mt() % sIn.size(); auto iter = sIn.begin(); while (id--) iter++; int i = *iter; remove(i); sIn.erase(i); return i; } int press() { numP++; return press_button(); } int min_cardinality(int N) { n = N; cnt = 0; numA = numP = 0; mt = mt19937(time(0)); in = vector<bool>(n); int cur = 0; for (int i = 0; i < n; i++) { add(i); cur = press(); if (cur > 1) { remove(i); sOut.insert(i); cur = 1; } } int typeCnt = cnt; int left = 1, right = n / typeCnt; bool up = true; restart: while (left < right) { int mid = (left + right + 1) / 2; unordered_set<int> later; try_up: if (up) { while (cnt < typeCnt * mid) { if (sOut.empty()) { right = mid - 1; up = false; for (auto &e : later) sOut.insert(e); later.clear(); goto restart; } int inc = mid - cur + 1; int recent = -1; while (!sOut.empty() && inc--) { recent = add_rand(); sIn.insert(recent); } cur = press(); if (cur > mid) { remove(recent); sIn.erase(recent); later.insert(recent); cur = mid; } } left = mid; up = true; sIn.clear(); for (auto &e : later) sOut.insert(e); later.clear(); } else { while (cur > mid) { int dec = cur - mid + 1; int recent = -1; while (dec--) { recent = remove_rand(); sOut.insert(recent); } cur = press(); if (cur < mid) { add(recent); sOut.erase(recent); later.insert(recent); cur = mid; } } up = true; for (auto &e : later) sIn.insert(e); later.clear(); goto try_up; } } return left; } #ifdef TEST #include "grader.cpp" #endif
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...