# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
311648 | andrew | Counting Mushrooms (IOI20_mushrooms) | C++17 | 0 ms | 0 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>
#define fi first
#define se second
#define p_b push_back
#define m_p make_pair
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define pw(x) (1 << x);
using namespace std;
typedef long long ll;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;
ll count_mushrooms(int n){
vector <int> m(n);
iota(all(m), 0);
int x = use_machine(m);
if(x == 0)return n;
m = {0, 1};
int xt = use_machine(m);
if(x == 1 && xt == 1)return 1;
int uk = 2, ans = 2;
int wh = 1;
if(xt){
int mx = 0;
for(int i = 0; i <= 20; i++){
if(pw(i) + 1 > n)break;
m.resize(pw(i) + 1);
iota(all(m), 0);
if(use_machine(m) > 1)break;
mx = i;
}
wh = pw(mx);
for(int i = mx - 1; i >= 0; i--)if(wh + pw(i) < n){
m.resize(pw(i) + wh + 1);
iota(all(m), 0);
if(use_machine(m) == 1)wh += pw(i);
}
wh++;
}
uk = wh + 1;
while(uk + 1 < n){
m = {0, uk, wh, uk + 1};
int x = use_machine(m);
ans += 2 - ((x + 1) / 2);
uk += 2;
}
if(uk == n - 1){
m = {0, uk};
if(use_machine(m) == 0)ans++;
}
return ans;
}