# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
760065 | aryan12 | 버섯 세기 (IOI20_mushrooms) | C++17 | 0 ms | 208 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |