#include<bits/stdc++.h>
#include "mushrooms.h"
using namespace std;
int count_mushrooms(int n)
{
vector<int>nr[2];
vector<int>aux;
nr[0].push_back(0);
int i,lim=130,ok,cnt=0,rez,ok2,ram,j;
for(i=1;i<n && max(nr[0].size(),nr[1].size())<2;i++)
nr[use_machine({0,i})].push_back(i);
if (nr[1].size()==2)
ok=1;
else
ok=0;
for(;i<n && max(nr[0].size(),nr[1].size())<lim;i=i+2)
{
if (i+1<n)
rez=use_machine({nr[ok][0],i,nr[ok][1],i+1});
else
rez=use_machine({nr[ok][0],i,nr[ok][1]});
if (rez&2)
ok2=1;
else
ok2=0;
nr[ok^ok2].push_back(i);
if (i+1<n)
ok2=rez&1,nr[ok^ok2].push_back(i+1);
}
while(i<n)
{
if (nr[1].size()==max(nr[0].size(),nr[1].size()))
ok=1;
else
ok=0;
ram=min((int)max(nr[0].size(),nr[1].size()),n-i);
aux.clear();
for(j=0;j<ram;j++)
aux.push_back(nr[ok][j]),aux.push_back(i+j);
rez=use_machine(aux);
if (rez%2==1)
rez++;
if (ok)
cnt=cnt+rez/2;
else
cnt=cnt+rez-rez/2;
i+=ram;
}
return nr[0].size()+cnt;
}
Compilation message
mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:16:47: warning: comparison of integer expressions of different signedness: 'const long unsigned int' and 'int' [-Wsign-compare]
16 | for(;i<n && max(nr[0].size(),nr[1].size())<lim;i=i+2)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Incorrect |
4 ms |
384 KB |
Answer is not correct. |
7 |
Halted |
0 ms |
0 KB |
- |