# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
720558 | bin9638 | Counting Mushrooms (IOI20_mushrooms) | C++17 | 1 ms | 208 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;
vector<int>A,B;
int count_mushrooms(int cc)
{
n=cc;
A.clear();
B.clear();
A.pb(0);
int res=1;
for(int i=1;i<n;)
{
if(A.size()>B.size())
{
vector<int>hoi;
for(int j=i;j<min(n,i+(int)A.size());j++)
{
hoi.pb(j);
hoi.pb(A[j-i]);
}
int val=use_machine(hoi);
res+=((val+1)/2);
if(val&1)
A.pb(i);
else B.pb(i);
i+=A.size();
}else
{
vector<int>hoi;
int cnt=0;
for(int j=i;j<min(n,i+(int)B.size());j++)
{
hoi.pb(j);
hoi.pb(B[j-i]);
cnt++;
}
int val=use_machine(hoi);
res+=(cnt-((val+1)/2));
if(val&1)
B.pb(i);
else A.pb(i);
i+=B.size();
}
}
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... |