#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);
}
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
{
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;
}
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";
}**/
Compilation message
mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:57:22: warning: 'k' may be used uninitialized in this function [-Wmaybe-uninitialized]
57 | if (k&1)
| ~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Incorrect |
1 ms |
256 KB |
Answer is not correct. |
7 |
Halted |
0 ms |
0 KB |
- |