# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
718450 | baojiaopisu | Counting Mushrooms (IOI20_mushrooms) | C++14 | 11 ms | 512 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>
#include <iostream>
#include <algorithm>
#include <array>
#include <random>
#include <chrono>
using namespace std;
#define pb push_back
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int count_mushrooms(int n) {
vector<int> a, b;
vector<int> not_solved;
for(int i = 1; i < n; i++) not_solved.pb(i);
a.pb(0);
shuffle(not_solved.begin(), not_solved.end(), rng);
int res = 1;
while(not_solved.size()) {
if(a.size() >= b.size()) {
if(a.size() >= 150) {
vector<int> r;
while(not_solved.size() && r.size() < a.size()) {
r.pb(not_solved.back());
not_solved.pop_back();
}
vector<int> ask;
for(int i = 0; i < (int)a.size(); i++) {
if(i < r.size()) ask.pb(r[i]);
ask.pb(a[i]);
}
int x = use_machine(ask);
res += r.size() - ((x + 1) / 2);
if(x & 1) {
b.pb(r[0]);
swap(r[0], r[r.size() - 1]);
r.pop_back();
} else {
a.pb(r[0]);
swap(r[0], r[r.size() - 1]);
r.pop_back();
}
} else {
if(a.size() == 1 || not_solved.size() == 1) {
int u = not_solved.back();
not_solved.pop_back();
if(use_machine({a[0], u})) {
b.pb(u);
} else {
++res;
a.pb(u);
}
} else {
int u = not_solved.back();
not_solved.pop_back();
int v = not_solved.back();
not_solved.pop_back();
int d = use_machine({a[0], u, a[1], v});
if(d & 1) b.pb(v); else a.pb(v), res++;
if(d & 2) b.pb(u); else a.pb(u), res++;
}
}
} else {
if(b.size() >= 150) {
vector<int> r;
while(not_solved.size() && r.size() < b.size()) {
r.pb(not_solved.back());
not_solved.pop_back();
}
vector<int> ask;
for(int i = 0; i < (int)b.size(); i++) {
if(i < r.size()) ask.pb(r[i]);
ask.pb(b[i]);
}
int x = use_machine(ask);
if(x & 1) {
a.pb(r[0]);
swap(r[0], r[r.size() - 1]);
r.pop_back();
} else {
b.pb(r[0]);
swap(r[0], r[r.size() - 1]);
r.pop_back();
}
res += (x + 1) / 2;
} else {
if(b.size() == 1 || not_solved.size() == 1) {
int u = not_solved.back();
not_solved.pop_back();
if(use_machine({b[0], u})) {
a.pb(u);
++res;
} else b.pb(u);
} else {
int u = not_solved.back();
not_solved.pop_back();
int v = not_solved.back();
not_solved.pop_back();
int d = use_machine({b[0], u, b[1], v});
if(d & 1) a.pb(v), res++; else b.pb(v);
if(d & 2) a.pb(u), res++; else b.pb(u);
}
}
}
}
return res;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |