# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
817741 | math_rabbit_1028 | Counting Mushrooms (IOI20_mushrooms) | C++14 | 8 ms | 444 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "mushrooms.h"
#include <bits/stdc++.h>
using namespace std;
int count_mushrooms(int n) {
int b = sqrt(0.75 * n);
vector<int> Alist, Blist;
Alist.push_back(0);
int i, ans = Alist.size();
if (n <= 200) {
for (int i = 1; i < n; i++) if (use_machine({Alist[0], i}) == 0) ans++;
return ans;
}
if (use_machine({0, 1}) == 0) {
Alist.push_back(1);
for (i = 2; i < n; i += 2) {
int ret = use_machine({Alist[0], i, Alist[1], i + 1});
if (ret >= 2) Blist.push_back(i);
else Alist.push_back(i);
if (ret % 2 == 0) Alist.push_back(i + 1);
else Blist.push_back(i + 1);
if (Alist.size() >= 3 && Blist.size() >= 2) break;
if (Alist.size() >= 2 && Blist.size() >= 3) break;
if (Alist.size() >= b || Blist.size() >= b) break;
}
}
else {
Blist.push_back(1);
if (use_machine({0, 2}) == 0) {
Alist.push_back(2);
for (i = 3; i < n; i += 2) {
int ret = use_machine({Alist[0], i, Alist[1], i + 1});
if (ret >= 2) Blist.push_back(i);
else Alist.push_back(i);
if (ret % 2 == 0) Alist.push_back(i + 1);
else Blist.push_back(i + 1);
if (Alist.size() >= 3 && Blist.size() >= 2) break;
if (Alist.size() >= 2 && Blist.size() >= 3) break;
if (Alist.size() >= b || Blist.size() >= b) break;
}
}
else {
Blist.push_back(2);
for (i = 3; i < n; i += 2) {
int ret = use_machine({Blist[0], i, Blist[1], i + 1});
if (ret >= 2) Alist.push_back(i);
else Blist.push_back(i);
if (ret % 2 == 0) Blist.push_back(i + 1);
else Alist.push_back(i + 1);
if (Alist.size() >= 3 && Blist.size() >= 2) break;
if (Alist.size() >= 2 && Blist.size() >= 3) break;
if (Alist.size() >= b || Blist.size() >= b) break;
}
}
}
i += 2;
if (Alist.size() >= 3 && Blist.size() >= 2) {
for (; i < n; i += 5) {
int ret = use_machine({Alist[0], i, Alist[1], i + 1, Alist[2], i + 2}), ret2;
if (ret == 0) {
Alist.push_back(i);
Alist.push_back(i + 1);
Alist.push_back(i + 2);
}
if (ret == 1) {
Alist.push_back(i);
Alist.push_back(i + 1);
Blist.push_back(i + 2);
}
if (ret == 4) {
Blist.push_back(i);
Blist.push_back(i + 1);
Alist.push_back(i + 2);
}
if (ret == 5) {
Blist.push_back(i);
Blist.push_back(i + 1);
Blist.push_back(i + 2);
}
if (ret == 0 || ret == 1 || ret == 4 || ret == 5) {
ret2 = use_machine({Alist[0], i + 3, Alist[1], i + 4});
}
if (ret == 2 || ret == 3) {
ret2 = use_machine({Blist[0], i, Blist[1], Alist[0], i + 1, Alist[1], i + 3, Alist[2], i + 4}) - 1;
if (ret2 >= 4) {
Alist.push_back(i);
Blist.push_back(i + 1);
ret2 -= 4;
}
else {
Blist.push_back(i);
Alist.push_back(i + 1);
}
if (ret == 2) Alist.push_back(i + 2);
if (ret == 3) Blist.push_back(i + 2);
}
if (ret2 >= 2) Blist.push_back(i + 3);
else Alist.push_back(i + 3);
if (ret2 % 2 == 0) Alist.push_back(i + 4);
else Blist.push_back(i + 4);
if (Alist.size() >= b || Blist.size() >= b) break;
}
i += 5;
}
else if (Alist.size() >= 2 && Blist.size() >= 3) {
for (; i < n; i += 5) {
int ret = use_machine({Blist[0], i, Blist[1], i + 1, Blist[2], i + 2}), ret2;
if (ret == 0) {
Blist.push_back(i);
Blist.push_back(i + 1);
Blist.push_back(i + 2);
}
if (ret == 1) {
Blist.push_back(i);
Blist.push_back(i + 1);
Alist.push_back(i + 2);
}
if (ret == 4) {
Alist.push_back(i);
Alist.push_back(i + 1);
Blist.push_back(i + 2);
}
if (ret == 5) {
Alist.push_back(i);
Alist.push_back(i + 1);
Alist.push_back(i + 2);
}
if (ret == 0 || ret == 1 || ret == 4 || ret == 5) {
ret2 = use_machine({Blist[0], i + 3, Blist[1], i + 4});
}
if (ret == 2 || ret == 3) {
ret2 = use_machine({Alist[0], i, Alist[1], Blist[0], i + 1, Blist[1], i + 3, Blist[2], i + 4}) - 1;
if (ret2 >= 4) {
Blist.push_back(i);
Alist.push_back(i + 1);
ret2 -= 4;
}
else {
Alist.push_back(i);
Blist.push_back(i + 1);
}
if (ret == 2) Blist.push_back(i + 2);
if (ret == 3) Alist.push_back(i + 2);
}
if (ret2 >= 2) Alist.push_back(i + 3);
else Blist.push_back(i + 3);
if (ret2 % 2 == 0) Blist.push_back(i + 4);
else Alist.push_back(i + 4);
if (Alist.size() >= b || Blist.size() >= b) break;
}
i += 5;
}
ans = Alist.size();
for (; i < n; ) {
vector<int> seq;
if (Alist.size() >= Blist.size()) {
for (int j = i; j < min(i + (int)Alist.size(), n); j++) {
seq.push_back(Alist[j - i]);
seq.push_back(j);
}
int ret = use_machine(seq);
ans += (min(i + (int)Alist.size(), n) - i) - (ret + 1) / 2;
i += Alist.size();
if (ret % 2 == 0) Alist.push_back(i - 1);
if (ret % 2 == 1) Blist.push_back(i - 1);
}
else {
for (int j = i; j < min(i + (int)Blist.size(), n); j++) {
seq.push_back(Blist[j - i]);
seq.push_back(j);
}
int ret = use_machine(seq);
ans += (ret + 1) / 2;
i += Blist.size();
if (ret % 2 == 0) Blist.push_back(i - 1);
if (ret % 2 == 1) Alist.push_back(i - 1);
}
}
return ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |