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 : Nguyen Tuan Vu
* Created : 03.01.2023
**/
#pragma GCC optimize("O2")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define MASK(x) ((1ll)<<(x))
#define BIT(x, i) (((x)>>(i))&(1))
#define ALL(v) (v).begin(), (v).end()
#define REP(i, n) for (int i = 0, _n = (n); i < _n; ++i)
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, b, a) for (int i = (b), _a = (a); i >= _a; --i)
template <class X, class Y> bool minimize(X &a, Y b) {
if (a > b) return a = b, true;
return false;
}
template <class X, class Y> bool maximize(X &a, Y b) {
if (a < b) return a = b, true;
return false;
}
using namespace std;
mt19937 jdg(chrono::steady_clock::now().time_since_epoch().count());
int Rand(int l, int r) {return l + jdg() % (r - l + 1);}
const int N = 2e3 + 5;
set <int> machine;
void move_inside(int i);
void move_outside(int i);
int press_button();
long long min_cardinality(int n) {
FOR(i, 1, n) {
move_inside(i);
if (press_button() > 1) move_outside(i);
else machine.insert(i);
}
//for (auto x : machine) cout << x << ' ';
//cout << '\n';
int distinct = machine.size();
int sign = 0;
int l = 1, r = n / machine.size() + 1;
while (r - l > 1) {
int mid = (l + r) >> 1;
if (sign == 0) {
FOR(i, 1, n) if (machine.find(i) == machine.end()) {
move_inside(i);
if (press_button() > mid) {
move_outside(i);
}
else {
machine.insert(i);
}
}
if (machine.size() == distinct * mid) l = mid;
else {
sign = 1;
r = mid;
}
}
else {
set <int> cur = machine;
for (auto x : machine) {
move_outside(x);
}
machine.clear();
for (auto x : cur) {
move_inside(x);
if (press_button() > mid) move_outside(x);
else machine.insert(x);
}
if (machine.size() == distinct * mid) sign = 0, l = mid;
else {
sign = 1;
r = mid;
}
}
//cout << l << ' ' << r << ' ' << sign << '\n';
}
return l;
}
Compilation message (stderr)
insects.cpp: In function 'long long int min_cardinality(int)':
insects.cpp:65:32: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
65 | if (machine.size() == distinct * mid) l = mid;
| ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
insects.cpp:85:32: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
85 | if (machine.size() == distinct * mid) sign = 0, l = mid;
| ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |