# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1003000 | MilosMilutinovic | Counting Mushrooms (IOI20_mushrooms) | C++14 | 6 ms | 716 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) {
if (n <= 227) {
int res = 1;
for (int i = 1; i < n; i++) {
res += 1 - use_machine({0, i});
}
return res;
}
const int C = 80;
vector<int> a(1, 0);
vector<int> b;
for (int i = 1; i <= 2; i++) {
if (use_machine({0, i})) {
b.push_back(i);
} else {
a.push_back(i);
}
}
int res = (int) a.size();
int ptr = 3;
while ((int) a.size() < C && (int) b.size() < C) {
if (ptr >= n) {
break;
}
if (ptr + 2 >= n) {
for (int i = ptr; i < n; i++) {
if (use_machine({0, i}) == 0) {
res += 1;
a.push_back(i);
}
}
ptr = n;
break;
}
int x = ptr, y = ptr + 1, z = ptr + 2;
if (a.size() > b.size()) {
int p = use_machine({x, a[0], y, a[1], z});
if (p == 0) {
res += 3;
a.push_back(x);
a.push_back(y);
a.push_back(z);
ptr += 3;
} else if (p == 4) {
b.push_back(x);
b.push_back(y);
b.push_back(z);
ptr += 3;
} else if (p == 2) {
int d = ptr + 3;
int q = use_machine({a[0], y, a[1], d});
if (q >= 2) {
a.push_back(x);
a.push_back(z);
res += 2;
b.push_back(y);
} else {
a.push_back(y);
res += 1;
b.push_back(x);
b.push_back(z);
}
if (q % 2 == 1) {
b.push_back(d);
} else {
a.push_back(d);
res += 1;
}
ptr += 4;
} else if (p == 1) {
int d = ptr + 3;
int q = use_machine({a[0], x, a[1], d});
if (q >= 2) {
b.push_back(x);
a.push_back(y);
a.push_back(z);
res += 2;
} else {
a.push_back(x);
a.push_back(y);
res += 2;
b.push_back(z);
}
if (q % 2 == 1) {
b.push_back(d);
} else {
a.push_back(d);
res += 1;
}
ptr += 4;
} else {
int d = ptr + 3;
int q = use_machine({a[0], x, a[1], d});
if (q >= 2) {
b.push_back(x);
b.push_back(y);
a.push_back(z);
res += 1;
} else {
a.push_back(x);
res += 1;
b.push_back(y);
b.push_back(z);
}
if (q % 2 == 1) {
b.push_back(d);
} else {
a.push_back(d);
res += 1;
}
ptr += 4;
}
} else {
int p = 4 - use_machine({x, b[0], y, b[1], z});
if (p == 0) {
res += 3;
a.push_back(x);
a.push_back(y);
a.push_back(z);
ptr += 3;
} else if (p == 4) {
b.push_back(x);
b.push_back(y);
b.push_back(z);
ptr += 3;
} else if (p == 2) {
int d = ptr + 3;
int q = 3 - use_machine({b[0], y, b[1], d});
if (q >= 2) {
a.push_back(x);
a.push_back(z);
res += 2;
b.push_back(y);
} else {
a.push_back(y);
res += 1;
b.push_back(x);
b.push_back(z);
}
if (q % 2 == 1) {
b.push_back(d);
} else {
a.push_back(d);
res += 1;
}
ptr += 4;
} else if (p == 1) {
int d = ptr + 3;
int q = 3 - use_machine({b[0], x, b[1], d});
if (q >= 2) {
b.push_back(x);
a.push_back(y);
a.push_back(z);
res += 2;
} else {
a.push_back(x);
a.push_back(y);
res += 2;
b.push_back(z);
}
if (q % 2 == 1) {
b.push_back(d);
} else {
a.push_back(d);
res += 1;
}
ptr += 4;
} else {
int d = ptr + 3;
int q = 3 - use_machine({b[0], x, b[1], d});
if (q >= 2) {
b.push_back(x);
b.push_back(y);
a.push_back(z);
res += 1;
} else {
a.push_back(x);
res += 1;
b.push_back(y);
b.push_back(z);
}
if (q % 2 == 1) {
b.push_back(d);
} else {
a.push_back(d);
res += 1;
}
ptr += 4;
}
}
}
if (ptr >= n) {
return res;
}
while (ptr < n) {
if (a.size() > b.size()) {
int c = min(n - ptr, (int) a.size());
vector<int> qv;
for (int i = 0; i < c; i++) {
qv.push_back(a[i]);
qv.push_back(ptr + i);
}
int d = use_machine(qv);
if (d % 2 == 0) {
a.push_back(qv.back());
res += 1;
} else {
b.push_back(qv.back());
}
res += (c - 1 - (d / 2));
ptr += c;
} else {
int c = min(n - ptr, (int) b.size());
vector<int> qv;
for (int i = 0; i < c; i++) {
qv.push_back(b[i]);
qv.push_back(ptr + i);
}
int d = use_machine(qv);
if (d % 2 == 0) {
b.push_back(qv.back());
} else {
a.push_back(qv.back());
res += 1;
}
res += d / 2;
ptr += c;
}
}
return res;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |