# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
825546 | Edu175 | Counting Mushrooms (IOI20_mushrooms) | C++17 | 16 ms | 352 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
#define fst first
#define snd second
#define fore(i,a,b) for(ll i=a,ioi=b;i<ioi;i++)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define mset(a,v) memset((a),(v),sizeof(a))
#define imp(v) for(auto dfh:v)cout<<dfh<<" ";cout<<"\n"
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
const ll MAXN=2e4+5;
ll ask(vector<ll>a){
vector<int>ai;
for(auto i:a)ai.pb(i);
return use_machine(ai);
}
map<ii,ll>did;
ll ran(ll l, ll r){ //[,]
if(did.count({l,r}))return did[{l,r}];
ll &res=did[{l,r}];
if(l==r)return res=0;
vector<ll>a;
fore(i,l,r+1)a.pb(i);
return res=ask(a);
}
int count_mushrooms(int n){
ll res=0;
ll p=0,k=ran(0,n-1)+1;
ll c=0;
while(k>1){
//cout<<p<<" "<<k<<" "<<c<<": ";
ll l=p,r=n-k;
while(l<=r){
ll m=(l+r)/2;
if(ran(p,m)+1==1)l=m+1;
else r=m-1;
}
if(!c)res+=l-p;
//cout<<l<<"\n";
p=l;
c^=1;
k--;
}
if(!c)res+=n-p;
return res;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |