#include <bits/stdc++.h>
#include "mushrooms.h"
using namespace std;
int count_mushrooms(int n) {
vector<int> A = {0}, B;
int x = use_machine({0, 1});
int start = 2;
if (x == 0) A.push_back(1);
else {
B.push_back(1);
if (n <= 2) return A.size();
x = use_machine({0, 2});
if (x == 0) A.push_back(2);
else B.push_back(2);
start = 3;
}
for (int i = start; i < n; i += 2) {
if (i + 1 < n) {
if (A.size() >= 2) {
x = use_machine({A[0], i, A[1], i + 1});
if (x == 0) A.push_back(i), A.push_back(i + 1);
if (x == 1) A.push_back(i), B.push_back(i + 1);
if (x == 2) A.push_back(i + 1), B.push_back(i);
if (x == 3) B.push_back(i), B.push_back(i + 1);
}
else {
x = use_machine({B[0], i, B[1], i + 1});
if (x == 0) B.push_back(i), B.push_back(i + 1);
if (x == 1) B.push_back(i), A.push_back(i + 1);
if (x == 2) B.push_back(i + 1), A.push_back(i);
if (x == 3) A.push_back(i), A.push_back(i + 1);
}
}
else {
x = use_machine({0, i});
if (x == 0) A.push_back(i);
else B.push_back(i);
}
}
return A.size();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |