# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
738535 | bobthebuilder | Counting Mushrooms (IOI20_mushrooms) | C++17 | 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;
#define sz(x) (int)x.size()
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define pb push_back
#define lowb(x) (x&(-x))
#define ALL(_x) _x.begin(),_x.end()
#define pii pair<int,int>
#define f first
#define s second
#define SORT_UNIQUE(x) sort(ALL(x)),x.erase(unique(ALL(x)),x.end())
#define ll long long
#define MNTO(x,y) x=min(x,y)
#define MXTO(x,y) x=max(x,y)
int count_mushrooms(int n) {
const int blk=3;
if(n<=2){
int ans=1;
REP1(i,n-1){
ans+=1-use_machine({0,i});
}
return ans;
}
vector<int> v[2];
v[0].pb(0);
int z=use_machine({0,1}),zz=use_machine({0,2});
if(z) v[1].pb(1);
else v[0].pb(1);
if(zz) v[1].pb(2);
else v[0].pb(2);
for(int i=3;i<2*blk-1;i+=2){
if(sz(v[0])>=2){
int k=use_machine({i,v[0][0],i+1,v[0][1]});
v[k%2].pb(i),v[k/2].pb(i+1);
}
else{
int k=use_machine({i,v[1][0],i+1,v[1][1]});
v[1-k%2].pb(i),v[1-k/2].pb(i+1);
}
}
int mx=max(sz(v[0]),sz(v[1]));
int ans=0;
for(int i=2*blk-1;i<n;i+=mx){
mx=max(sz(v[0]),sz(v[1]));
vector<int> vv;
int p=0;
if(sz(v[1])==mx) p=1;
REP(j,mx){
if(i+j>=n) break;
vv.pb(i+j);
vv.pb(v[p][j]);
}
int k=use_machine(vv);
v[(k%2)^(p)].pb(i);
ans+=(p?k/2:sz(vv)/2-k/2-1);
}
//for(int x:v[0]) cout<<x<<' ';
ans+=sz(v[0]);
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |