#include<bits/stdc++.h>
#include "mushrooms.h"
using namespace std;
int count_mushrooms(int n) {
vector<int> one , two , m;
int lol , ek , dui;
one.clear();
two.clear();
int here = 1;
one.push_back(0);
for( int z = 1; z < min( 3 , n ); z++ ) {
m.clear();
m = {0 , here};
lol = use_machine(m);
if( lol == 1 ){
two.push_back(here);
here++;
}
else{
one.push_back(here);
here++;
}
}
int typ = 0;
if( (int)two.size() == 2 ) {
swap( one , two );
typ = 1;
}
while( here + 1 < min(n , 135) ) {
m.clear();
m.push_back(here);
m.push_back(one[0]);
m.push_back(here + 1);
m.push_back(one[1]);
int lel = use_machine(m);
if( (lel & 1) > 0 ) two.push_back(here);
else one.push_back(here);
if( (lel & 2) > 0 ) two.push_back(here + 1);
else one.push_back(here + 1);
here += 2;
}
if( typ == 1 ) swap( one , two );
ek = one.size();
dui = two.size();
while( here < n ) {
if( one.size() >= two.size() ) {
if( one.size() == 1 ) {
m.clear();
m = {0 , here};
lol = use_machine(m);
if( lol == 1 ){
two.push_back(here);
dui++;
here++;
}
else{
one.push_back(here);
here++;
ek++;
}
}
else{
m.clear();
m.push_back(0);
for( int z = 1; z < (int)one.size(); z++ ) {
if( here < n - 1 ) {
m.push_back(here);
here++;
}
m.push_back(one[z]);
}
m.push_back(here);
here++;
lol = use_machine(m);
if( lol % 2 == 0 ) {
one.push_back(here - 1);
ek++;
}
else{
lol--;
two.push_back(here - 1);
dui++;
}
lol = lol / 2;
dui += lol;
ek = (here - dui);
}
}
else{
m.clear();
m.push_back(two[0]);
for( int z = 1; z < (int)two.size(); z++ ) {
if( here < n - 1 ) {
m.push_back(here);
here++;
}
m.push_back(two[z]);
}
m.push_back(here);
here++;
lol = use_machine(m);
if( lol % 2 == 0 ) {
two.push_back(here - 1);
dui++;
}
else{
lol--;
one.push_back(here - 1);
ek++;
}
lol = lol / 2;
ek += lol;
dui = (here - ek);
}
}
cerr << ek << " " << dui << "\n";
return ek;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |