# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
604713 | CyberCow | Counting Mushrooms (IOI20_mushrooms) | C++17 | 16 ms | 536 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 <vector>
using namespace std;
int a[20006];
int mi[20006];
int count_mushrooms(int n) {
int l = 0, r = n - 1;
vector<int>v;
int i, j;
for (i = 0; i < n; i++)
{
v.push_back(i);
}
int qan = use_machine(v);
int zr = 0, mazr = 0;
a[qan] = n - 1;
for (i = 0; i < qan; i++)
{
zr = 0;
mazr = 0;
if (i)
l = a[i - 1] + 1;
for (j = i + 1; j <= qan; j++)
{
if (a[j])
{
r = a[j] - 1;
break;
}
}
if (i && a[i - 1] + 2 == a[i + 1])
{
a[i] = a[i - 1] + 1;
continue;
}
while (l <= r)
{
int m = (l + r) >> 1;
if (!m)
break;
v.clear();
int q = 0;
if (i)q = a[i - 1] + 1;
for (j = q; j <= m; j++)
{
v.push_back(j);
}
int x;
if (v.size() > 1)
x = use_machine(v);
else
x = 0;
a[i + x] = max(m, a[i + x]);
mi[i + x] = min(m, mi[i + x]);
if (x > 0)
{
r = m - 1;
}
else
{
l = m + 1;
}
}
}
int ans = a[0];
if (qan % 2)
qan--;
for (i = 1; i < qan; i += 2)
{
ans += a[i + 1] - a[i];
}
return ans + 1;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |