#ifndef davele
#include "insects.h"
#endif // davele
#include <bits/stdc++.h>
//#define int long long
#define pii pair<int, int>
#define fi first
#define se second
#define vi vector <int>
#define pq priority_queue
#define MASK(i) (1ll<<(i))
#define BIT(x, i) (((x) >> (i)) & 1)
#define x0 ___x0
#define y0 ___y0
#define div ___div
#define next ___next
#define prev ___prev
#define left ___left
#define right ___right
#define pos pisosi
#define pb push_back
#define pf push_front
using namespace std;
//const int mod = ;
//void add (int &a, const int&b){
// a+=b;
// if (a>=mod) a-=mod;
//}
//
//void sub (int&a, const int&b){
// a-=b;
// if (a<0) a+=mod;
//}
//
//void mul (int&a, const int&b){
// a*=b;
// a%=mod;
//}
template<class X, class Y>
bool minimize(X &x, const Y&y){
if (x<=y) return false;
else{
x = y;
return true;
}
}
template<class X, class Y>
bool maximize (X &x, const Y&y){
if (x>=y) return false;
else{
x = y;
return true;
}
}
////////////////////////////////////////////////////////////////////////////
const int lim = 2e3, limit = lim+5;
int n, useful[limit];
#ifdef davele
int cnti, cnto, cntp;
int A[limit], ts[limit];
void move_inside( int i ){
cnti++;
// cerr<<"i "<<i<<"\n";
ts[A[i]]++;
}
void move_outside (int i){
cnto++;
// cerr<<"o "<<i<<"\n";
ts[A[i]]--;
}
int press_button(){
cntp++;
// cerr<<"p \n";
int ret = 1;
for (int i=0; i<=lim; i++) maximize (ret, ts[i]);
return ret;
}
#endif // davele
int min_cardinality (int N){
n = N;
int numDiff = 0;
for (int i=0; i<n; i++){
move_inside(i);
if (press_button()>1){
move_outside(i);
useful[i] = 0;
}
else{
useful[i] = 1;
numDiff++;
}
}
int left = 2, right = N/numDiff, ret = 1;
int numInside = numDiff;
while (left<=right){
int mid = (left+right)/2;
for (int i=0; i<n; i++){
if (useful[i]>mid){ // (1) Xu ly nhung thang ton dong o phase truoc (chi co duy nhat 1 thang bi thua thoi!
move_outside(i);
numInside --;
useful[i] = 0; // Nhung thang co tiem nang trong cac dot sau
}
}
for (int i=0; i<n; i++){
if (useful[i]!=0) continue;
move_inside(i);
numInside++;
if (press_button()>mid){
numInside--;
move_outside(i);
}
else{
useful[i] = mid;
}
}
if (numInside!=numDiff*mid){
right = mid-1;
for (int i=0; i<n; i++){
if (useful[i]==0) useful[i] = -1; // nhung thang vo dung
// Nguoc lai, dua ve (1)
}
}
else{
ret = mid;
left = mid+1;
}
}
return ret;
}
/*
signed main(){
freopen("insects.inp", "r", stdin);
freopen("insects.out", "w", stdout);
int n;
cin>>n;
for (int i=0; i<n; i++) cin>>A[i];
cout<<min_cardinality(n);
cerr<<"inside "<<cnti<<" outside "<<cnto<<" press "<<cntp<<"\n";
}
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |