#include "mushrooms.h"
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
const int x=100;
vector<int> a,b,v;
int count_mushrooms(int n) {
    int c;
    if(n==2)
    {
        c=use_machine({0,1});
        if(c==1)return 1;
        return 2;
    }
    int ans=1;
    a.push_back(0);
    c=use_machine({0,1,2});
    if(c==2)
    {
        a.push_back(1);
        b.push_back(2);
        ans++;
    }
    if(c==0)
    {
        a.push_back(1);
        a.push_back(2);
        ans+=2;
    }
    if(c==1)
    {
        c=use_machine({0,1});
        if(c==1)b.pb(1);
        else ans++,a.pb(1);
        b.push_back(2);
    }
    int i=3;
    while(i<n)
    {
        if(a.size()>b.size())
        {
            vector<int> h;
            for(int j=0;j<a.size();j++)
            {
                h.push_back(a[j]);
                if(i==n)break;
                h.push_back(i++);
            }
            c=use_machine(h);
            ans+=h.size()/2-c;
            if(h.size()%2==0)
            {
                if(c%2==0)a.pb(h[h.size()-1]);
                else b.pb(h[h.size()-1]);
            }
        }
        else
        {
            vector<int> h;
            for(int j=0;j<b.size();j++)
            {
                h.push_back(b[j]);
                if(i==n)break;
                h.push_back(i++);
            }
            c=use_machine(h);
            ans+=h.size()/2;
            if(h.size()%2==0)
            {
                if(c%2==0)b.pb(h[h.size()-1]);
                else a.pb(h[h.size()-1]);
            }
        }
    }
    return ans;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |