# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
413120 | two_sides | Counting Mushrooms (IOI20_mushrooms) | C++17 | 14 ms | 328 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;
int count_mushrooms(int N) {
if (N <= 227) {
int cnt = 1;
for (int i = 1; i < N; i++)
cnt += !use_machine({0, i});
return cnt;
}
vector <int> pos[2];
pos[0].push_back(0);
pos[use_machine({0, 1})].push_back(1);
pos[use_machine({0, 2})].push_back(2);
int K = 0.97 * sqrt(N), ptr = 3;
if (pos[0].size() > 1) {
while (max(pos[0].size(),
pos[1].size()) < K) {
int x = use_machine({ptr,
pos[0][0], ptr + 1, pos[0][1]});
pos[x % 2].push_back(ptr);
pos[x / 2].push_back(ptr + 1);
ptr += 2;
}
} else {
while (max(pos[0].size(),
pos[1].size()) < K) {
int x = use_machine({ptr,
pos[1][0], ptr + 1, pos[1][1]});
pos[1 - x % 2].push_back(ptr);
pos[1 - x / 2].push_back(ptr + 1);
ptr += 2;
}
}
int cnt = pos[0].size();
while (ptr < N) {
if (pos[0].size() >= pos[1].size()) {
vector <int> tmp; int len = 0;
for (int i = 0; i < pos[0].size()
&& ptr < N; i++, ptr++) {
tmp.push_back(ptr); len++;
tmp.push_back(pos[0][i]);
}
int x = use_machine(tmp);
cnt += len - x / 2 - x % 2;
pos[x % 2].push_back(tmp[0]);
} else {
vector <int> tmp;
for (int i = 0; i < pos[1].size()
&& ptr < N; i++, ptr++) {
tmp.push_back(ptr);
tmp.push_back(pos[1][i]);
}
int x = use_machine(tmp);
cnt += x / 2 + x % 2;
pos[1 - x % 2].push_back(tmp[0]);
}
}
return cnt;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |