#include "mushrooms.h"
#include <vector>
#include <math.h>
using namespace std;
vector < int > A,B;
vector < int > temp;
int count_mushrooms(int N)
{
int k=floor(sqrt(2*N)),ans=0,x=0,y=0,i,now,tt;
for(i=1;i<=min(k,N-1);i++)
{
temp.clear();
temp.push_back(0);
temp.push_back(i);
if(use_machine(temp))
{
x++;
B.push_back(i);
}
else
{
y++;
A.push_back(i);
}
}
if(x>=y)
{
now=k+1;
while(now<N)
{
temp.clear();
for(auto i:B)
{
temp.push_back(i);
if(now<N)
{
temp.push_back(now);
now++;
}
}
tt=use_machine(temp);
if(temp.size()>=2) ans+=(tt+1)/2;
//if(tt%2==0) B.push_back(*prev(temp.end()));
}
}
else
{
now=k+1;
while(now<N)
{
temp.clear();
for(auto i:A)
{
temp.push_back(i);
if(now<N)
{
temp.push_back(now);
now++;
}
}
tt=use_machine(temp);
if(temp.size()>=2) ans+=(temp.size()-y-(tt+1)/2);
if(tt%2==1) A.push_back(*prev(temp.end()));
}
}
ans+=y;
return ans+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 |
2 ms |
256 KB |
Answer is not correct. |
7 |
Halted |
0 ms |
0 KB |
- |