#include "mushrooms.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n;
int count_mushrooms(int N) {
n = N;
if (n <= 900) {
vector<int> A, B;
A.push_back(0);
int p;
for (p = 2;p < n;p += 2) {
if (A.size() < 2 && B.size() < 2) {
int v = use_machine({ p - 1, 0, p });
if (v == 0) {
A.push_back(p);
A.push_back(p - 1);
}
else if (v == 2) {
B.push_back(p);
B.push_back(p - 1);
}
else {
if (use_machine({ 0, p })) B.push_back(p), A.push_back(p - 1);
else B.push_back(p - 1), A.push_back(p);
}
}
else if (A.size() >= 2) {
int v = use_machine({ A[0], p - 1, A[1], p });
if (v & 1) B.push_back(p);
else A.push_back(p);
if (v & 2) B.push_back(p - 1);
else A.push_back(p - 1);
}
else {
int v = use_machine({ B[0], p - 1, B[1], p });
if (!(v & 1)) B.push_back(p);
else A.push_back(p);
if (!(v & 2)) B.push_back(p - 1);
else A.push_back(p - 1);
}
}
p--;
if (p == n - 1) {
if (use_machine({ 0, p })) B.push_back(p);
else A.push_back(p);
}
return (int)A.size();
}
int sq = 282;
vector<int> A, B;
A.push_back(0);
int p;
for (p = 2;p < sq;p += 2) {
if (A.size() < 2 && B.size() < 2) {
int v = use_machine({ p - 1, 0, p });
if (v == 0) {
A.push_back(p);
A.push_back(p - 1);
}
else if (v == 2) {
B.push_back(p);
B.push_back(p - 1);
}
else {
if (use_machine({ 0, p })) B.push_back(p), A.push_back(p - 1);
else B.push_back(p - 1), A.push_back(p);
}
}
else if (A.size() >= 2) {
int v = use_machine({ A[0], p - 1, A[1], p });
if (v & 1) B.push_back(p);
else A.push_back(p);
if (v & 2) B.push_back(p - 1);
else A.push_back(p - 1);
}
else {
int v = use_machine({ B[0], p - 1, B[1], p });
if (!(v & 1)) B.push_back(p);
else A.push_back(p);
if (!(v & 2)) B.push_back(p - 1);
else A.push_back(p - 1);
}
}
p--;
// count A from p -> n - 1
int ans = A.size();
while (p < n) {
int j;
if (A.size() > B.size()) {
int sz = A.size();
vector<int> Q;
for (j = p;j < min(n, p + sz);j++) {
Q.push_back(j);
Q.push_back(A[j - p]);
}
int v = use_machine(Q);
int s = Q.size();
ans += (s - v) / 2;
if (!(v & 1)) A.push_back(j - 1);
else B.push_back(j - 1);
}
else {
int sz = B.size();
vector<int> Q;
for (j = p;j < min(n, p + sz);j++) {
Q.push_back(j);
Q.push_back(B[j - p]);
}
int v = use_machine(Q);
ans += (v + 1) / 2;
if (v & 1) A.push_back(j - 1);
else B.push_back(j - 1);
}
p = j;
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
444 KB |
Output is correct |
6 |
Incorrect |
1 ms |
344 KB |
Answer is not correct. |
7 |
Halted |
0 ms |
0 KB |
- |