# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
720565 | bin9638 | Counting Mushrooms (IOI20_mushrooms) | C++17 | 10 ms | 516 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#ifndef SKY
#include "mushrooms.h"
#endif // SKY
using namespace std;
#define N 100010
#define ll long long
#define fs first
#define sc second
#define ii pair<int,int>
#define pb push_back
#ifdef SKY
int type[N];
int use_machine(vector<int>s)
{
int res=0;
for(int i=0;i<s.size()-1;i++)
res+=(type[s[i]]!=type[s[i+1]]);
return res;
}
#endif // SKY
int n,hv[N];
vector<int>A,B;
int count_mushrooms(int cc)
{
n=cc;
A.clear();
B.clear();
A.pb(0);
int res=1;
for(int i=0;i<n;i++)
hv[i]=i;
random_shuffle(hv+1,hv+n);
for(int i=1;i<n;)
{
if(A.size()>=B.size())
{
vector<int>hoi;
int cnt=0;
for(int j=i;j<min(n,i+(int)A.size());j++)
{
cnt++;
hoi.pb(hv[j]);
hoi.pb(A[j-i]);
}
int val=(cnt*2-1-use_machine(hoi));
res+=((val+1)/2);
if(val&1)
A.pb(hv[i]);
else B.pb(hv[i]);
i+=(A.size()-(val&1));
}else
{
vector<int>hoi;
int cnt=0;
for(int j=i;j<min(n,i+(int)B.size());j++)
{
hoi.pb(hv[j]);
hoi.pb(B[j-i]);
cnt++;
}
int val=(cnt*2-1-use_machine(hoi));
res+=(cnt-((val+1)/2));
if(val&1)
B.pb(hv[i]);
else A.pb(hv[i]);
i+=(B.size()-(val&1));
}
// cout<<res<<" "<<i<<endl;
}
return res;
}
#ifdef SKY
int main()
{
freopen("A.inp","r",stdin);
freopen("A.out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin>>n;
for(int i=0;i<n;i++)
cin>>type[i];
cout<<count_mushrooms(n);
return 0;
}
#endif
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |