# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
718253 | baojiaopisu | Counting Mushrooms (IOI20_mushrooms) | C++14 | 9 ms | 588 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()) {
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();
}
for(int i = 1; i <= 5; i++) {
if(r.empty() || a.size() >= 150) break;
if(a.size() == 1 || r.size() == 1) {
int u = r.back();
r.pop_back();
if(use_machine({a[0], u})) {
b.pb(u);
} else a.pb(u);
} else {
int u = r.back();
r.pop_back();
int v = r.back();
r.pop_back();
int d = use_machine({a[0], u, a[1], v});
if(d & 1) b.pb(v); else a.pb(v);
if(d & 2) b.pb(u); else a.pb(u);
}
}
} else {
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;
for(int i = 1; i <= 5; i++) {
if(r.empty() || b.size() >= 150) break;
if(b.size() == 1 || r.size() == 1) {
int u = r.back();
r.pop_back();
if(use_machine({b[0], u})) {
a.pb(u);
} else b.pb(u);
} else {
int u = r.back();
r.pop_back();
int v = r.back();
r.pop_back();
int d = use_machine({b[0], u, b[1], v});
if(d & 1) a.pb(v); else b.pb(v);
if(d & 2) a.pb(u); else b.pb(u);
}
}
}
}
return res;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |