# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
305233 | ScarletS | Counting Mushrooms (IOI20_mushrooms) | C++17 | 12 ms | 384 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 "mushrooms.h"
#include <bits/stdc++.h>
#define sz(x) (int)(x).size()
using namespace std;
/**
int N,a[20000],totalQ=0;
int use_machine(vector<int> v)
{
int k = sz(v), sendBack=0;
++totalQ;
for (int i=1;i<k;++i)
if (a[v[i]]!=a[v[i-1]])
++sendBack;
return sendBack;
}
**/
const int upkeep=80;
int count_mushrooms(int n) {
if (n<=226*2)
{
int ans=0;
for (int i = 1; i+1 < n; i+=2)
ans+=use_machine({i,0,i+1});
if (!(n&1))
ans+=use_machine({n-1,0});
return n-ans;
}
else
{
vector<int> v={0},w,m;
int x,y,doneTill=0,k;
while (max(sz(v),sz(w))<2)
{
if (use_machine({0,++doneTill}))
w.push_back(doneTill);
else
v.push_back(doneTill);
}
//cout<<sz(v)<<" "<<sz(w)<<"\n";
while (max(sz(v),sz(w))<upkeep)
{
if (sz(v)>sz(w))
{
k=use_machine({doneTill+1,v[0],doneTill+2,v[1]});
if (k&1)
w.push_back(doneTill+1);
else
v.push_back(doneTill+1);
if ((k>>1)&1)
w.push_back(doneTill+2);
else
v.push_back(doneTill+2);
}
else
{
k=use_machine({doneTill+1,w[0],doneTill+2,w[1]});
if (k&1)
v.push_back(doneTill+1);
else
w.push_back(doneTill+1);
if ((k>>1)&1)
v.push_back(doneTill+2);
else
w.push_back(doneTill+2);
}
doneTill+=2;
}
//cout<<sz(v)<<" "<<sz(w)<<"\n";
x=sz(v);y=sz(w);
while (doneTill+1<n)
{
m.clear();
if (sz(v)>sz(w))
{
for (int i=doneTill+1;i<=min(doneTill+sz(v),n-1);++i)
{
m.push_back(i);
m.push_back(0);
}
for (int i=1;i<sz(m);i+=2)
m[i]=v[(i>>1)];
k=use_machine(m);
if (k&1)
{
w.push_back(m[0]);
++y;
}
else
{
v.push_back(m[0]);
++x;
}
y+=(k>>1);
x+=(((sz(m)-1)>>1)-(k>>1));
}
else
{
for (int i=doneTill+1;i<=min(doneTill+sz(w),n-1);++i)
{
m.push_back(i);
m.push_back(0);
}
for (int i=1;i<sz(m);i+=2)
m[i]=w[(i>>1)];
k=use_machine(m);
if (k&1)
{
v.push_back(m[0]);
++x;
}
else
{
w.push_back(m[0]);
++y;
}
x+=(k>>1);
y+=(((sz(m)-1)>>1)-(k>>1));
}
doneTill=m[sz(m)-2];
}
return x;
}
}
/**
int main()
{
cin>>N;
for (int i=0;i<N;++i)
cin>>a[i];
cout<<count_mushrooms(N)<<"\n";
cout<<totalQ<<" queries\n";
}**/
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |