# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
588341 | supercatex | Counting Mushrooms (IOI20_mushrooms) | C++14 | 1 ms | 208 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 check_1(int x1)
{
return use_machine(vector<int>{0, x1});
}
void check_2(int x1, int x2, vector<int> &a, vector<int> &b)
{
int x = use_machine(vector<int>{x1, a[0], x2});
if (x == 0) {
a.push_back(x1);
a.push_back(x2);
} else if (x == 2) {
b.push_back(x1);
b.push_back(x2);
} else {
if (check_1(x1) == 0) {
a.push_back(x1);
b.push_back(x2);
} else {
a.push_back(x2);
b.push_back(x1);
}
}
}
void check_3(int x1, int x2, int x3, vector<int> &a, vector<int> &b)
{
if (b.size() > 0) {
int x = use_machine(vector<int>{x1, a[0], x2, b[0], x3});
if (x == 1) {
a.push_back(x1);
b.push_back(x3);
if (check_1(x2) == 0) {
a.push_back(x2);
} else {
b.push_back(x2);
}
} else if (x == 2) {
if (check_1(x1) == 0) {
a.push_back(x1);
b.push_back(x2);
a.push_back(x3);
} else {
b.push_back(x1);
a.push_back(x2);
b.push_back(x3);
}
} else if (x == 3) {
b.push_back(x1);
a.push_back(x3);
if (check_1(x2) == 0) {
a.push_back(x2);
} else {
b.push_back(x2);
}
}
} else {
int x = use_machine(vector<int>{x1, a[0], x2, a[1], x3});
if (x == 0) {
a.push_back(x1);
a.push_back(x2);
a.push_back(x3);
} else if (x == 1) {
if (check_1(x1) == 0) {
a.push_back(x1);
a.push_back(x2);
b.push_back(x3);
} else {
b.push_back(x1);
a.push_back(x2);
a.push_back(x3);
}
} else if (x == 2) {
if (check_1(x1) == 0) {
a.push_back(x1);
b.push_back(x2);
a.push_back(x3);
} else {
b.push_back(x1);
a.push_back(x2);
b.push_back(x3);
}
} else if (x == 3) {
if (check_1(x1) == 0) {
a.push_back(x1);
b.push_back(x2);
b.push_back(x3);
} else {
b.push_back(x1);
b.push_back(x2);
a.push_back(x3);
}
} else if (x == 4) {
b.push_back(x1);
b.push_back(x2);
b.push_back(x3);
}
}
}
int count_mushrooms(int n)
{
vector<int> a = {0}, b;
check_2(1, 2, a, b);
int i = 3;
while (i + 2 < n) {
check_3(i, i + 1, i + 2, a, b);
i = i + 3;
}
if (n % 3 == 2) check_2(n - 1, n - 2, a, b);
else if (n % 3 == 1)
if (check_1(n - 1) == 0)
a.push_back(n - 1);
else
b.push_back(n - 1);
return a.size();
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |