#include "insects.h"
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#pragma GCC target("popcnt")
using namespace std;
using ll = long long;
using ull = unsigned long long;
using lld = long double;
using ii = pair<int,int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vii = vector<ii>;
using vpll = vector<pll>;
using vlld = vector<lld>;
#define all(x) x.begin(),x.end()
#define lsb(x) x&(-x)
#define gcd(a,b) __gcd(a,b)
#define sz(x) (int)x.size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define fls cout.flush()
#define fore(i, l, r) for (auto i = l; i < r; i++)
#define fo(i, n) fore (i, 0, n)
#define forex(i, r, l) for (auto i = r-1; i >= l; i--)
#define ffo(i, n) forex (i, n, 0)
bool cmin(ll &a, ll b) { if (b < a) { a=b; return 1; } return 0; }
bool cmax(ll &a, ll b) { if (b > a) { a=b; return 1; } return 0; }
/*
void move_inside(i)
void move_outside(i)
ll press_button()
*/
int min_cardinality(int n) {
vll A;
fo (i, n) {
move_inside(i);
if (press_button() == 2) {
move_outside(i);
continue;
}
A.pb(i);
}
for (ll i: A) move_outside(i);
if (A.size() == 1) return n;
ll l = 2, r = n/A.size();
set<ll> wh, act;
fo (i, n) act.insert(i);
while (l <= r) {
ll m = (l+r)/2;
vll ok;
for (ll i: act) {
if (wh.find(i) != wh.end()) continue;
if (wh.size() == A.size()*m) continue;
move_inside(i);
wh.insert(i);
if (press_button() > m) {
wh.erase(i);
move_outside(i);
} else {
ok.push_back(i);
}
}
if (wh.size() == A.size()*m) {
l = m+1;
} else {
r = m-1;
act = wh;
for (ll i: ok) {
move_outside(i);
wh.erase(i);
}
}
}
return r;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |