# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
410992 | SeDunion | Counting Mushrooms (IOI20_mushrooms) | C++17 | 12 ms | 712 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 K;
int askline(int l, int r) {
vector<int>toquest;
for (int i = l ; i <= r ; ++ i) toquest.emplace_back(i);
return use_machine(toquest);
}
using vi = vector<int>;
int count_mushrooms(int n) {
if (n == 2) {
return 2 - use_machine({0, 1});
}
K = min(n, 100);
if (K % 2 == 0) K--;
vector<int>who(n, 2); // 0 -> A, 1 -> B, 2 -> unknown
who[0] = 0;
for (int p = 0 ; p < 2 ; ++ p) {
int ret = use_machine({p, p + 1});
who[p + 1] = who[p] ^ (ret & 1);
}
for (int p = 3 ; p < K - 1 ; p += 2) {
vector<int>v = (!who[1] ? vi{0, 1} : (who[2] ? vi{1, 2} : vi{0, 2}));
cerr << p << " " << p + 1 << " as\n";
int ret = use_machine(vi{p, v[0], p + 1, v[1]});
who[p] = (who[v[0]] && !(ret & 1)) || (!who[v[0]] && ret & 1);
who[p + 1] = (who[v[0]] && ret <= 1) || (!who[v[0]] && (ret & 2));
}
array<vector<int>, 3>vecs;
for (int i = 0 ; i < n ; ++ i) {
vecs[who[i]].emplace_back(i);
}
int answer = (int)vecs[0].size();
for (int i = 0 ; i < (int)vecs[2].size() ;) {
auto &p = (vecs[0].size() > vecs[1].size() ? vecs[0] : vecs[1]);
vector<int>ask;
int l = i, r = min((int)vecs[2].size(), i + (int)p.size()) - 1;
for (int j = l ; j <= r ; ++ j) {
ask.emplace_back(vecs[2][j]);
ask.emplace_back(p[j-l]);
}
i = r + 1;
int ret = use_machine(ask);
answer += (p == vecs[0] ? r-l+1 - (ret+1)/2 : (ret+1)/2);
int first = ((p == vecs[0] && ret % 2) || (p == vecs[1] && ret % 2 == 0));
vecs[first].emplace_back(vecs[2][l]);
}
return answer;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |