# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
390872 | AlexPop28 | Counting Mushrooms (IOI20_mushrooms) | C++14 | 13 ms | 392 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;
#ifdef LOCAL_DEFINE
const int K = 3;
#else
const int K = 100;
#endif
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int count_mushrooms(int n) {
if (n <= K) {
int ans = 0;
for (int i = 1; i < n; ++i) {
vector<int> curr = {0, i};
ans += use_machine(curr);
}
return n - ans;
}
vector<int> val(n, -1);
vector<int> pos_a, pos_b;
auto Get = [&]() {
int pos = rng() % n;
while (val[pos] >= 0) pos = rng() % n;
return pos;
};
auto A = [&](int x) {
assert(val[x] == -1);
pos_a.emplace_back(x);
val[x] = 0;
};
auto B = [&](int x) {
assert(val[x] == -1);
pos_b.emplace_back(x);
val[x] = 1;
};
A(0);
while((int)max(pos_a.size(), pos_b.size()) < 2) {
int pos = Get();
vector<int> curr = {0, pos};
if (use_machine(curr) == 0) {
A(pos);
} else {
B(pos);
}
}
if (pos_a.size() > pos_b.size()) { // am 2 A
while((int)max(pos_a.size(), pos_b.size()) < K) {
int pos0 = Get(), pos1 = Get();
vector<int> curr = {pos_a[0], pos0, pos_a[1], pos1};
int val = use_machine(curr);
if (val == 0) {
A(pos0); A(pos1);
} else if (val == 1) {
A(pos0); B(pos1);
} else if (val == 2) {
B(pos0); A(pos1);
} else {
B(pos0); B(pos1);
}
}
} else { // am 2 B
while((int)max(pos_a.size(), pos_b.size()) < K) {
int pos0 = Get(), pos1 = Get();
vector<int> curr = {pos_b[0], pos0, pos_b[1], pos1};
int val = use_machine(curr);
if (val == 0) {
B(pos0); B(pos1);
} else if (val == 1) {
B(pos0); A(pos1);
} else if (val == 2) {
A(pos0); B(pos1);
} else {
A(pos0); A(pos1);
}
}
}
bool type = false;
auto pos = pos_a;
if (pos_b.size() > pos_a.size()) {
type = true;
pos = pos_b;
}
int ans = pos_a.size();
int i = 1;
while (i < n) {
vector<int> curr;
for (int j = 0; j < K; ++j) {
curr.emplace_back(pos[j]);
while (i < n && val[i] >= 0) ++i;
if (i == n) break;
if (j + 1 < K) curr.emplace_back(i++);
}
int total = (curr.size() - 1) / 2;
int ret = use_machine(curr) / 2;
if (!type) ret = total - ret;
ans += ret;
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |