# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1052608 | TahirAliyev | Counting Mushrooms (IOI20_mushrooms) | C++17 | 6 ms | 760 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>
using namespace std;
#define pii pair<int, int>
#define ll long long
#define all(v) v.begin(), v.end()
#define oo 1e9
int count_mushrooms(int n){
srand(time(0));
//
int B = 78;
// pair<int, int> best = {oo, 0};
// for(int x = 3; x <= n; x++) best = min(best, {2 + (2 * (x - 2)) / 2 + (x & 1) + (n - 1) / x, x});
// B = best.second;
//
vector<int> id;
for(int i = 0; i < n; i++) id.push_back(i);
random_shuffle(id.begin() + 1, id.end());
vector<int> v[2];
v[0] = {0};
int i = 1;
for(; i < min(3, n); i++){
v[use_machine({0, id[i]})].push_back(i);
}
int t = (v[0].size() < v[1].size());
for(; i + 1 < n && (int)max(v[0].size(), v[1].size()) < B; i += 2){
int a = use_machine({id[i], id[v[t][0]], id[i + 1], id[v[t][1]]});
v[t ^ (a & 1)].push_back(i);
v[t ^ bool(a & 2)].push_back(i + 1);
}
if(i == n - 1){
v[use_machine({0, id[i]})].push_back(i);
i++;
}
int ans = v[0].size();
if(i == n) return ans;
while(i < n){
t = (v[0].size() < v[1].size());
vector<int> tmp;
for(int j = 0; j < v[t].size() && i < n; j++, i++){
tmp.push_back(id[v[t][j]]);
tmp.push_back(id[i]);
}
int a = use_machine(tmp);
if(a & 1) v[t ^ 1].push_back(i - 1);
else v[t].push_back(i - 1);
if(t) ans += (a + 1) / 2;
else ans += (tmp.size() / 2) - (a + 1) / 2;
}
return ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |