Submission #1052428

#TimeUsernameProblemLanguageResultExecution timeMemory
1052428Huseyn123Counting Mushrooms (IOI20_mushrooms)C++17
80.71 / 100
5 ms852 KiB
#include "mushrooms.h" #include <bits/stdc++.h> #define pb push_back using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int count_mushrooms(int n) { vector<int> c; for(int i=1;i<n;i++){ c.push_back(i); } shuffle(c.begin(),c.end(),rng); vector<int> v0,v1; v0.push_back(0); int res=(int)v0.size(); vector<int> v=v0; int tp=0; if((int)v1.size()>(int)v0.size()){ tp=1; } vector<int> d; int mx=max((int)v0.size(),(int)v1.size()); for(int i=0;i<n-1;i++){ if(tp==0){ d.push_back(v0[(int)d.size()/2]); } else{ d.push_back(v1[(int)d.size()/2]); } d.push_back(c[i]); if((int)d.size()==2*mx){ int h=use_machine(d); int sz=(int)d.size(); d.clear(); if(tp){ res+=h/2+h%2; if(h%2){ v0.pb(c[i]); } else{ v1.pb(c[i]); } } else{ res+=sz/2-h/2-h%2; if(h%2){ v1.pb(c[i]); } else{ v0.pb(c[i]); } } } if((int)v0.size()>(int)v1.size()){ tp=0; } else{ tp=1; } mx=max((int)v0.size(),(int)v1.size()); } if((int)d.size()>0){ int h=use_machine(d); int sz=(int)d.size(); d.clear(); if(tp){ res+=h/2+h%2; } else{ res+=sz/2-h/2-h%2; } } return res; }
#Verdict Execution timeMemoryGrader output
Fetching results...