This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*************************************
* author: marvinthang *
* created: 25.08.2022 22:19:29 *
*************************************/
#include <bits/stdc++.h>
#include "insects.h"
using namespace std;
#define fi first
#define se second
#define div ___div
#define left ___left
#define right ___right
#define TIME (1.0 * clock() / CLOCKS_PER_SEC)
#define MASK(i) (1LL << (i))
#define FULL(i) (MASK(i) - 1)
#define BIT(x, i) ((x) >> (i) & 1)
#define __builtin_popcount __builtin_popcountll
#define scan_op(...) istream & operator >> (istream &in, __VA_ARGS__ &u)
#define print_op(...) ostream & operator << (ostream &out, const __VA_ARGS__ &u)
#define file(name) if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }
template <class T> scan_op(vector <T>) { for (size_t i = 0; i < u.size(); ++i) in >> u[i]; return in; }
template <class T> print_op(vector <T>) { out << '{'; for (size_t i = 0; i + 1 < u.size(); ++i) out << u[i] << ", "; if (!u.empty()) out << u.back(); return out << '}'; }
template <class U, class V> scan_op(pair <U, V>) { return in >> u.fi >> u.se; }
template <class U, class V> print_op(pair <U, V>) { return out << '(' << u.fi << ", " << u.se << ')'; }
const double PI = 3.1415926535897932384626433832795; // acos(-1.0); atan(-1.0);
const int dir[] = {1, 0, -1, 0, 1, 1, -1, -1, 1}; // {2, 1, -2, -1, -2, 1, 2, -1, 2};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long rand(long long l, long long h) { return uniform_int_distribution <long long> (l, h) (rng); }
set <int> insides;
vector <int> order;
void add(int i) {
move_inside(order[i]);
insides.insert(i);
}
void remove(int i) {
move_outside(order[i]);
insides.erase(i);
}
void reset_machine(void) {
set <int> tmp = insides;
for (int i: tmp) remove(i);
}
int min_cardinality(int n) {
order.resize(n);
iota(order.begin(), order.end(), 0);
shuffle(order.begin(), order.end(), rng);
for (int i = 0; i < n; ++i) {
add(i);
if (press_button() > 1) remove(i);
}
map <int, set <int>> machine_states;
machine_states[1] = insides;
for (int i = 0; i < n; ++i) machine_states[n].insert(i);
int unique_vals = insides.size();
int l = 2, r = n / unique_vals;
while (l <= r) {
int m = l + r >> 1;
auto it = machine_states.lower_bound(m);
set <int> just_added;
for (int i: it->se) if (!insides.count(i)) {
add(i);
if (press_button() > m) remove(i);
else just_added.insert(i);
if (insides.size() >= unique_vals * m) break;
}
int total = insides.size();
machine_states[m] = insides;
if (total >= unique_vals * m) l = m + 1;
else {
r = m - 1;
for (int i: just_added) remove(i);
}
}
return r;
}
Compilation message (stderr)
insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:68:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
68 | int m = l + r >> 1;
| ~~^~~
insects.cpp:75:23: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
75 | if (insides.size() >= unique_vals * m) break;
| ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |