# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
936447 | EJIC_B_KEDAX | Counting Mushrooms (IOI20_mushrooms) | C++17 | 7 ms | 852 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 ll = long long;
using namespace std;
const int lovv66 = 83;
mt19937 mt(time(nullptr));
int count_mushrooms(int n) {
vector<int> p(n - 1);
for (int i = 0; i < n - 1; i++) {
p[i] = i + 1;
}
if (n - 1 >= 2) {
shuffle(p.begin(), p.end(), mt);
use_machine(p);
}
shuffle(p.begin(), p.end(), mt);
vector<int> a(1, 0), b;
int x = 0, ans = 1;
int iter = 0;
while (x < n - 1) {
vector<int> ask;
if (a.size() > b.size()) {
int ind = 0, len = -1, start = x;
while (x < n - 1 && ind < a.size() && (iter >= lovv66 || ind < 2)) {
ask.push_back(a[ind++]);
ask.push_back(p[x++]);
len++;
}
int cnt = use_machine(ask);
if (cnt & 1) {
b.push_back(p[x - 1]);
} else {
a.push_back(p[x - 1]);
ans++;
}
cnt /= 2;
if (!cnt) {
for (int i = start; i < x - 1; i++) {
a.push_back(p[i]);
}
} else if (cnt == len) {
for (int i = start; i < x - 1; i++) {
b.push_back(p[i]);
}
}
ans += len - cnt;
} else {
int ind = 0, len = -1, start = x;
while (x < n - 1 && ind < b.size() && (iter >= lovv66 || ind < 2)) {
ask.push_back(b[ind++]);
ask.push_back(p[x++]);
len++;
}
int cnt = use_machine(ask);
if (cnt & 1) {
a.push_back(p[x - 1]);
ans++;
} else {
b.push_back(p[x - 1]);
}
cnt /= 2;
if (!cnt) {
for (int i = start; i < x - 1; i++) {
b.push_back(p[i]);
}
} else if (cnt == len) {
for (int i = start; i < x - 1; i++) {
a.push_back(p[i]);
}
}
ans += cnt;
}
iter++;
}
return ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |