# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1055597 | Trent | Counting Mushrooms (IOI20_mushrooms) | C++17 | 10 ms | 1376 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;
#define forR(i, x) for(int i = 0; i < (x); ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define all(x) x.begin(), x.end()
typedef vector<int> vi;
typedef vector<bool> vb;
typedef long long ll;
typedef vector<ll> vll;
typedef set<int> si;
int count_mushrooms(int n) {
int IVL = n <= 200 ? 1 : 140;
vi chk;
for(int i = 0; i < n; i += IVL) chk.push_back(i);
if(chk.back() < n-1) chk.push_back(n-1);
vi ty(chk.size());
ty[0] = 0;
REP(i, 1, chk.size()) {
vi tst = {0, chk[i]};
ty[i] = use_machine(tst) == 0 ? 0 : 1;
}
vi ac, bc;
forR(i, chk.size()) {
if(ty[i] == 0) ac.push_back(chk[i]);
else bc.push_back(chk[i]);
}
vb usd(n, false);
for(int i : chk) usd[i] = true;
si emp;
forR(i, n) if(!usd[i]) emp.insert(i);
int tot = ac.size();
while(!emp.empty()) {
int amt = min(max(ac.size(), bc.size()), emp.size() + 1);
if(ac.size() > bc.size()) {
vi qu;
forR(i, amt - 1) {
qu.push_back(ac[i]);
qu.push_back(*emp.begin());
emp.erase(qu.back());
}
qu.push_back(ac[amt - 1]);
int ret = use_machine(qu);
cerr << qu.size() << ' ' << ret << '\n';
tot += amt - 1 - ret / 2;
} else {
vi qu;
forR(i, amt - 1) {
qu.push_back(bc[i]);
qu.push_back(*emp.begin());
emp.erase(qu.back());
}
qu.push_back(bc[amt - 1]);
int ret = use_machine(qu);
cerr << qu.size() << ' ' << ret << '\n';
tot += ret / 2;
}
}
return tot;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |