# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
760065 | aryan12 | Counting Mushrooms (IOI20_mushrooms) | C++17 | 0 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 count_mushrooms(int n)
{
vector<int> a_type, b_type;
a_type.push_back(0);
int current_mushroom = 1;
int answer = 0;
const int brute_force = 60;
while(current_mushroom < n)
{
if(max((int)a_type.size(), (int)b_type.size()) <= brute_force
and max((int)a_type.size(), (int)b_type.size()) >= 2
and current_mushroom != n - 1)
{
vector<int> query;
if((int)a_type.size() >= 2)
{
query.push_back(a_type[0]);
query.push_back(current_mushroom);
query.push_back(a_type[1]);
query.push_back(current_mushroom + 1);
int response = use_machine(query);
if(response >= 2)
{
b_type.push_back(current_mushroom);
}
else
{
a_type.push_back(current_mushroom);
}
if(response & 1)
{
b_type.push_back(current_mushroom + 1);
}
else
{
a_type.push_back(current_mushroom + 1);
}
current_mushroom += 2;
}
else if((int)b_type.size() >= 2)
{
query.push_back(b_type[0]);
query.push_back(current_mushroom);
query.push_back(b_type[1]);
query.push_back(current_mushroom + 1);
int response = use_machine(query);
if(response >= 2)
{
a_type.push_back(current_mushroom);
}
else
{
b_type.push_back(current_mushroom);
}
if(response & 1)
{
a_type.push_back(current_mushroom + 1);
}
else
{
b_type.push_back(current_mushroom + 1);
}
current_mushroom += 2;
}
else
{
assert(false);
}
}
if(a_type.size() > b_type.size())
{
// use a_type.size()
int cnt = min((int)a_type.size(), n - 1 - current_mushroom + 1);
vector<int> query;
for(int i = 0; i < cnt; i++)
{
query.push_back(a_type[i]);
query.push_back(current_mushroom + i);
}
int response = use_machine(query);
int last_one = current_mushroom + cnt - 1;
if(response & 1) // last one is b_type
{
b_type.push_back(last_one);
response -= 1;
}
else
{
a_type.push_back(last_one);
}
int total = query.size() - 2;
answer += (total - response) / 2;
current_mushroom += cnt;
}
else
{
int cnt = min((int)b_type.size(), n - 1 - current_mushroom + 1);
vector<int> query;
for(int i = 0; i < cnt; i++)
{
query.push_back(b_type[i]);
query.push_back(current_mushroom + i);
}
int response = use_machine(query);
int last_one = current_mushroom + cnt - 1;
if(response & 1)
{
a_type.push_back(last_one);
response -= 1;
}
else
{
b_type.push_back(last_one);
}
answer += response / 2;
current_mushroom += cnt;
}
}
return answer + (int)a_type.size();
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |