# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
430088 | dreezy | Counting Mushrooms (IOI20_mushrooms) | C++17 | 1578 ms | 1560 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"
using namespace std;
#define pb push_back
#define mp make_pair
set<pair<vector<int>, int>> queries;
int use(vector<int> q){
auto it = lower_bound(queries.begin(), queries.end(), mp(q, -1));
if(it != queries.end() && it->first == q){
return it->second;
}
int res = use_machine(q);
queries.insert({q, res});
return res;
}
int geta(int l, int r){
if( l > r) return 0;
if(l == r)
return use({0,l}) == 0;
vector<int> inds;
for(int i = l; i <=r; i++)inds.pb(i);
int res = use(inds);
if(res == 0){
if(use({0, l})== 0)
return r - l + 1;
else
return 0;
}
else if(res == r -l){
if((r - l + 1)%2 == 0) return (r - l + 1)/2;
else {
if(use({0,l}) == 0){
return (r - l + 1)/2 + 1;
}
else
return (r - l + 1)/2;
}
}
else if(res == 1){
int lo = l;
int hi = r;
int target = !use({0, lo});
while(lo!= hi){
int mi = (lo + hi)/2;
if( use({0,mi}) == target){
hi = mi;
}
else{
lo = mi + 1;
}
}
if(target == 1){//we were looking for the first B
//cout << l <<", "<<r <<": "<<lo<<endl;
return lo - l;
}
else{//we were looking for the first A
return r - lo + 1;
}
}
int mid = (l + r)/2;
return geta( l, mid) + geta(mid + 1, r);
}
int count_mushrooms(int n) {
queries.clear();
int ans = 1;
for(int block = 1; block <n; block += ceil(sqrt(n))){
ans += geta(block, min((int)ceil(sqrt(n)) + block -1 , n -1) );
}
return ans;
}
/************************/
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |