# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
409398 | Carmel_Ab1 | Counting Mushrooms (IOI20_mushrooms) | C++17 | 3 ms | 584 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 <bits/stdc++.h>
#include "mushrooms.h"
//#include "stub.cpp"
using namespace std;
#define pb push_back
typedef vector<int> vi;
typedef long long ll;
int ceil(int a,int b){
int ans=a/b;
if(a%b)
ans++;
return ans;
}
int count_mushrooms(int n) {
int ans=1;
if(n<=226){
for(int i=2; i<n; i++)
ans+=1- use_machine({0,i});
return ans;
}
vi o,z,a(n,-1);
a[0]=0;
z.pb(0);
if(use_machine({0,1})){
o.pb(1);
a[1]=1;
}
else{
ans++;
a[1]=0;
z.pb(1);
}
if(use_machine({0,2})){
o.pb(2);
a[2]=1;
}
else{
ans++;
a[2]=0;
z.pb(2);
}
int first=1;
const int k=100;
bool z2=z.size()==2;
for(int i=3;z2 && o.size()<k && z.size()<k;first+=2, i+=2){
int res= use_machine({z[0],i,z[1],i+1});
if(res==0){
ans+=2;
z.pb(i);
z.pb(i+1);
a[i]=a[i+1]=0;
}
else if(res==1){
ans++;
z.pb(i);
o.pb(i+1);
a[i]=0,a[i+1]=1;
}
else if(res==2){
ans++;
o.pb(i);
z.pb(i+1);
a[i]=1,a[i+1]=0;
}
else if(res==3){
o.pb(i);
o.pb(i+1);
a[i]=1,a[i+1]=1;
}
}
for(int i=3;!z2 && o.size()<k && z.size()<k;first+=2, i+=2){
int res= use_machine({o[0],i,o[1],i+1});
if(res==0){
o.pb(i);
o.pb(i+1);
a[i]=a[i+1]=1;
}
else if(res==1){
ans++;
o.pb(i);
z.pb(i+1);
a[i]=1,a[i+1]=0;
}
else if(res==2){
ans++;
z.pb(i);
o.pb(i+1);
a[i]=0,a[i+1]=1;
}
else if(res==3){
ans+=2;
z.pb(i);
z.pb(i+1);
a[i]=0,a[i+1]=0;
}
}
vi left;
for(int i=0; i<n;i++)
if(a[i]==-1)
left.pb(i);
if(o.size()>z.size()){
for(int i=0,j=0; i<n;j=0, i++){
if(a[i]!=-1)continue;
vi cur;
while(left.size() && cur.size()+2<=n && j<o.size()){
cur.pb(o[j]);
cur.pb(left.back());
left.pop_back();
j++;
}
if(cur.size()>=2)
ans+= ceil(use_machine(cur),2);
}
}
else{
for(int i=0,j=0; i<n;j=0, i++){
if(a[i]!=-1)continue;
int in=0;
vi cur;
while(left.size() && cur.size()+2<=n && j<z.size()){
cur.pb(z[j]);
cur.pb(left.back());
left.pop_back();
j++;
in++;
}
if(cur.size()>=2)
ans+= in-ceil(use_machine(cur),2);
}
}
return ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |