# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1005792 | thinknoexit | Counting Mushrooms (IOI20_mushrooms) | C++17 | 7 ms | 600 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;
using ll = long long;
int n;
int count_mushrooms(int N) {
n = N;
if (n <= 400) {
int ans = 1;
for (int i = 2;i < n;i += 2) {
int v = use_machine({ i - 1, 0, i });
if (v == 1) ans++;
else if (v == 0) ans += 2;
}
if ((n - 1) & 1) {
if (!use_machine({ 0, n - 1 })) ans++;
}
return ans;
}
int sq = 113;
vector<int> A, B;
vector<int> P(n - 1);
iota(P.begin(), P.end(), 1);
random_shuffle(P.begin(), P.end());
A.push_back(0);
int p;
for (p = 2;p < n && (int)A.size() < sq && (int)B.size() < sq;p += 2) {
int v = use_machine({ P[p - 1], 0, P[p - 2] });
if (v == 0) {
A.push_back(P[p - 1]);
A.push_back(P[p - 2]);
}
else if (v == 2) {
B.push_back(P[p - 1]);
B.push_back(P[p - 2]);
}
else {
if (use_machine({ 0, P[p - 1] })) B.push_back(P[p - 1]), A.push_back(P[p - 2]);
else B.push_back(P[p - 2]), A.push_back(P[p - 1]);
}
}
p--;
// count A from p -> n - 1
int ans = A.size();
if (A.size() > B.size()) {
int sz = A.size();
for (int i = p, j;i < n;i = j) {
vector<int> Q;
for (j = i;j < min(n, i + sz - 1);j++) {
Q.push_back(P[j - 1]);
Q.push_back(A[j - i]);
}
int v = use_machine(Q);
int s = Q.size();
ans += (s - v) / 2;
}
}
else {
int sz = B.size();
for (int i = p, j;i < n;i = j) {
vector<int> Q;
for (j = i;j < min(n, i + sz - 1);j++) {
Q.push_back(P[j - 1]);
Q.push_back(B[j - i]);
}
int v = use_machine(Q);
ans += (v + 1) / 2;
}
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |