# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
699788 | grossly_overconfident | Counting Mushrooms (IOI20_mushrooms) | C++17 | 0 ms | 0 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"
int count_mushrooms(int n) {
if (n < 220){
int a = 1;
for (int i = 1; i < n; ++i){
a += 1 - use_machine({ 0, i });
}
return a;
}
vector<int> a(1, 0);
vector<int> b;
if (use_machine({ 0, 1 }) == 1){
b.push_back(1);
}
else{
a.push_back(1);
}
if (use_machine({ 0, 2 }) == 1){
b.push_back(2);
}
else{
a.push_back(2);
}
for (int i = 3; i <= 150; i += 2){
if (a.size() > b.size()){
int h = use_machine({ i, a[0], i + 1, a[1]});
if (h % 2){
a.push_back(i);
}
else{
b.push_back(i);
}
if (h < 2){
a.push_back(i + 1);
}
else{
b.push_back(i + 1);
}
}
else{
int h = use_machine({ i, b[0], i + 1, b[1]});
if (h % 2){
b.push_back(i);
}
else{
a.push_back(i);
}
if (h < 2){
b.push_back(i + 1);
}
else{
a.push_back(i + 1);
}
}
}
int i = 151;
int tally = a.size();
while (true){
if (a.size() < b.size()){
vector<int> p;
int w = i;
for (int j = 0; j < b.size(); ++j){
p.push_back(i);
p.push_back(b[j]);
i++;
if (i == n){
break;
}
}
h = use_machine(p);
if (h % 2 == 0){
b.push_back(w);
tally += h / 2;
}
else{
a.push_back(w);
tally++;
tally += (h - 1) / 2;
}
if (i == n){
return tally;
}
}
else{
vector<int> p;
int w = i;
for (int j = 0; j < a.size(); ++j){
p.push_back(i);
p.push_back(a[j]);
i++;
if (i == n){
break;
}
}
h = use_machine(p);
if (h % 2 == 0){
a.push_back(w);
tally++;
tally += (i - w) - (h / 2);
}
else{
b.push_back(w);
tally += (i - w) - ((h - 1) / 2);
}
if (i == n){
return tally;
}
}
if (i == n){
return tally;
}
}
}