# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
835690 | BT21tata | Counting Mushrooms (IOI20_mushrooms) | C++17 | 7 ms | 336 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>
#define pb push_back
using namespace std;
const int BLOCK=241;
vector<int>a, b;
int count_mushrooms(int n)
{
a.pb(0);
if(n<=220)
{
for(int i=1; i<n; i++)
{
int cnt=use_machine({0, i});
if(cnt) b.pb(i);
else a.pb(i);
}
return a.size();
}
if(use_machine({0, 1})) b.pb(1);
else a.pb(1);
if(use_machine({0, 2})) b.pb(2);
else a.pb(2);
for(int i=3; i<BLOCK; i+=2)
{
if(a.size()>=2)
{
int cnt=use_machine({i, a[0], i+1, a[1]});
if(!cnt) a.pb(i), a.pb(i+1);
else if(cnt==1) b.pb(i), a.pb(i+1);
else if(cnt==2) a.pb(i), b.pb(i+1);
else b.pb(i), b.pb(i+1);
}
else
{
int cnt=use_machine({i, b[0], i+1, b[1]});
if(!cnt) b.pb(i), b.pb(i+1);
else if(cnt==1) a.pb(i), b.pb(i+1);
else if(cnt==2) b.pb(i), a.pb(i+1);
else a.pb(i), a.pb(i+1);
}
}
if(a.size()>b.size())
{
int ansb=b.size();
for(int i=BLOCK; i<n; i+=(a.size()))
{
vector<int>cur;
int pos=0;
for(int j=i; j<min(n, (int)(i+a.size())); j++)
{
cur.pb(a[pos++]);
cur.pb(j);
}
int ret=use_machine(cur);
ansb+=((ret+1)/2);
if(!(ret&1)) a.pb(i+a.size()-1), i--;
}
return n-ansb;
}
else
{
int ansa=a.size();
for(int i=BLOCK; i<n; i+=(b.size()))
{
vector<int>cur;
int pos=0;
for(int j=i; j<min(n, (int)(i+b.size())); j++)
{
cur.pb(b[pos++]);
cur.pb(j);
}
int ret=use_machine(cur);
ansa+=((ret+1)/2);
if(!(ret&1)) b.pb(i+b.size()-1), i--;
}
return ansa;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |