Submission #1092525

#TimeUsernameProblemLanguageResultExecution timeMemory
1092525huyngoRarest Insects (IOI22_insects)C++17
99.89 / 100
53 ms1564 KiB
#include "insects.h" #include <bits/stdc++.h> using namespace std; using ll = long long; using i64 = long long; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cerr << x; } void __print(double x) { cerr << x; } void __print(long double x) { cerr << x; } void __print(char x) { cerr << '\'' << x << '\''; } void __print(const char* x) { cerr << '"' << x << '"'; } void __print(const string& x) { cerr << '"' << x << '"'; } void __print(bool x) { cerr << (x ? "true" : "false"); } template<typename T, typename V> void __print(const pair<T, V>& x) { cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}'; } template<typename T> void __print(const T& x) { int f = 0; cerr << '{'; for (auto& i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"; } void _print() { cerr << "]\n"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); } #define dbg(x...) cerr << "[" << #x << "] = ["; _print(x) #define ln "\n" #define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0) #define all(x) (x).begin(), (x).end() #define rep(i,a,b) for(int i=a; i<=b; ++i) #define ar array int Bit(int mask, int b) { return (mask >> b) & 1; } const ll base = 311, MOD = 998244353, M = 1e9 + 7, INF = 1e18; int min_cardinality(int N) { set<int> T; auto add = [&](int x) { T.insert(x); move_inside(x); }; auto del = [&](int x) { T.erase(x); move_outside(x); }; for (int i = 0; i < N; ++i) { add(i); if (press_button() > 1) del(i); } int n_species = T.size(); map<int, set<int>> states; states[1] = T; states[N] = set<int>(); for (int i = 0; i < N; ++i) states[N].insert(i); int lo = 2, hi = N / n_species, res = 1; while (lo <= hi) { int md = (lo + hi) / 2; vector<int> just_added; auto it = states.lower_bound(md)->second; for (int i : it) if (!T.count(i)) { add(i); if (press_button() > md) del(i); else just_added.push_back(i); } int x = T.size(); states[md] = T; if (x >= n_species * md) { res = md; lo = md + 1; } else { for (int i : just_added) del(i); hi = md - 1; } } return res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...