#include "mushrooms.h"
int count_mushrooms(int n) {
if (n <= 227) {
int count = 1, cur = 0;
for (int i = 1; i < n; ++i) {
if (use_machine({i - 1, i})) {
cur ^= 1;
}
count += !cur;
}
return count;
}
std::vector<int> A = {0}, B;
int count = 1;
int X = 100;
for (int cur = 0, i = 1; i < X; i++) {
int y = use_machine({i-1, i});
cur ^= y;
if (cur == 0)
++count, A.push_back(cur);
else
B.push_back(cur);
}
int amogus = std::max(A.size(), B.size());
int chosen = A.size() >= B.size() ? 0 : 1;
int l = X;
while (l < n) {
int r = std::min(n, l + amogus - 1) - 1;
std::vector<int> m;
if (0 == chosen) {
m = {A[0]};
for (int j = l, k = 1; j <= r; ++j, ++k) {
m.push_back(j);
m.push_back(A[k]);
}
count += (r - l + 1) - use_machine(m) / 2;
} else {
m = {B[0]};
for (int j = l, k = 1; j <= r; ++j, ++k) {
m.push_back(j);
m.push_back(B[k]);
}
count += use_machine(m) / 2;
}
l = r + 1;
}
return count;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Incorrect |
1 ms |
344 KB |
Duplicate value 0 in the query array. |
7 |
Halted |
0 ms |
0 KB |
- |