# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
303767 | imeimi2000 | Counting Mushrooms (IOI20_mushrooms) | C++17 | 13 ms | 412 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;
static int ask(string s, vector<int> A, const vector<int> &z, const vector<int> &o) {
vector<int> q;
int iz = 0, io = 0;
for (char c : s) {
if ('0' <= c && c <= '9') {
q.push_back(A[c - '0']);
}
else if (c == 'A') {
q.push_back(z[iz++]);
}
else {
q.push_back(o[io++]);
}
}
return use_machine(q);
}
int calc(string s, int x) {
for (int i = 0; i < int(s.length()); ++i) {
if ('0' <= s[i] && s[i] <= '9') {
s[i] = 'A' + ((x >> s[i] - '0') & 1);
}
}
int ret = 0;
for (int i = 1; i < int(s.length()); ++i) {
ret += s[i - 1] != s[i];
}
return ret;
}
int count_mushrooms(int n) {
const string start = "0A1A2A3A4";
string qu[9];
qu[0] = "01234A"; // (1, 0)
qu[1] = "01234A"; // (1, 0)
qu[2] = "012B3B4A"; // (1, 2)
qu[3] = "0124AAB3B"; // (2, 2)
qu[4] = "014A23BA"; // (2, 1)
qu[5] = "0124A3A"; // (2, 0)
qu[6] = "012A3A4A"; // (3, 0)
qu[7] = "01234A"; // (1, 0)
qu[8] = "01234A"; // (1, 0)
const int B = 100;
vector<int> A[2];
A[0].push_back(0);
int i = 1;
for (; i < n && int(max(A[0].size(), A[1].size())) < 2; ++i) {
A[use_machine({ 0, i })].push_back(i);
}
for (; i + 1 < n && int(max(A[0].size(), A[1].size())) < B; ) {
if (i + 4 < n && int(max(A[0].size(), A[1].size())) >= 4 && int(min(A[0].size(), A[1].size())) >= 2) {
vector<int> X;
while (int(X.size()) < 5) X.push_back(i++);
int b = A[0].size() > A[1].size() ? 0 : 1;
int ret1 = ask(start, X, A[b], A[1 - b]);
int ret2 = ask(qu[ret1], X, A[b], A[1 - b]);
int bit;
for (bit = 0; calc(start, bit) != ret1 || calc(qu[ret1], bit) != ret2; ++bit);
if (b) bit = 31 - bit;
for (int i = 0; i < 5; ++i) {
A[(bit >> i) & 1].push_back(X[i]);
}
}
else if (int(A[0].size()) >= 2) {
int ret = use_machine({ A[0][0], i, A[0][1], i + 1 });
A[ret % 2].push_back(i + 1);
A[ret / 2].push_back(i);
i += 2;
}
else {
int ret = use_machine({ A[1][0], i, A[1][1], i + 1 });
A[1 - ret % 2].push_back(i + 1);
A[1 - ret / 2].push_back(i);
i += 2;
}
}
int ret = A[0].size();
for (; i < n; ) {
if (A[0].size() > A[1].size()) {
vector<int> q1;
for (; i < n && q1.size() < A[0].size(); ++i) q1.push_back(i);
vector<int> q;
for (int i = 0; i < int(q1.size()); ++i) {
q.push_back(A[0][i]);
q.push_back(q1[i]);
}
int u = use_machine(q);
A[u % 2].push_back(q1.back());
ret += int(q1.size()) - (u + 1) / 2;
}
else {
vector<int> q1;
for (; i < n && q1.size() < A[1].size(); ++i) q1.push_back(i);
vector<int> q;
for (int i = 0; i < int(q1.size()); ++i) {
q.push_back(A[1][i]);
q.push_back(q1[i]);
}
int u = use_machine(q);
A[1 - u % 2].push_back(q1.back());
ret += (u + 1) / 2;
}
}
return ret;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |