#include "mushrooms.h"
#include <bits/stdc++.h>
using namespace std;
int count_mushrooms(int n) {
const auto Solve = [&](int size_limit) {
int ans = 1;
set<int> unknown;
for (int i = 1; i < n; i++) {
unknown.emplace(i);
}
vector<int> A, B;
A.emplace_back(0);
while (!unknown.empty() && (int) max(A.size(), B.size()) < size_limit) {
if (unknown.size() == 1 || max(A.size(), B.size()) == 1) {
// query A?
// can identify ?
int u = *begin(unknown);
unknown.erase(u);
if (use_machine({0, u}) == 1) {
B.emplace_back(u);
} else {
A.emplace_back(u);
ans += 1;
}
} else if (unknown.size() < 5 || max(A.size(), B.size()) < 3 || min(A.size(), B.size()) < 2) {
// query A?A?
// can identify both ?
bool swapped = A.size() < 2;
if (swapped) {
swap(A, B);
}
int u = *begin(unknown);
unknown.erase(u);
int v = *begin(unknown);
unknown.erase(v);
int q = use_machine({A[0], u, A[1], v});
if (q == 0) {
A.emplace_back(u);
A.emplace_back(v);
ans += swapped ? 0 : 2;
} else if (q == 1) {
A.emplace_back(u);
B.emplace_back(v);
ans += 1;
} else if (q == 2) {
B.emplace_back(u);
A.emplace_back(v);
ans += 1;
} else if (q == 3) {
B.emplace_back(u);
B.emplace_back(v);
ans += swapped ? 2 : 0;
}
if (swapped) {
swap(A, B);
}
} else {
// query A?A?A?
// if first and second ? is the same, can uniquely identify them
// otherwise, query B?BA?A?A?, where the first and second ? is the
// same as previously, and other 2 is new element
// can uniquely identify all of them
int oldA = A.size();
bool swapped = A.size() < B.size();
if (swapped) {
swap(A, B);
}
int u = *begin(unknown);
unknown.erase(u);
int v = *begin(unknown);
unknown.erase(v);
int w = *begin(unknown);
unknown.erase(w);
int q = use_machine({A[0], u, A[1], v, A[2], w});
if (q & 1) {
q--;
B.emplace_back(w);
} else {
A.emplace_back(w);
}
if (q == 0) {
A.emplace_back(u);
A.emplace_back(v);
} else if (q == 4) {
B.emplace_back(u);
B.emplace_back(v);
} else {
int c = *begin(unknown);
unknown.erase(c);
int d = *begin(unknown);
unknown.erase(d);
q = use_machine({B[0], u, B[1], A[0], v, A[1], c, A[2], d}) - 1;
if (q & 1) {
B.emplace_back(d);
} else {
A.emplace_back(d);
}
if (q & 2) {
B.emplace_back(c);
} else {
A.emplace_back(c);
}
if (q & 4) {
A.emplace_back(u);
B.emplace_back(v);
} else {
B.emplace_back(u);
A.emplace_back(v);
}
}
if (swapped) {
swap(A, B);
}
ans += int(A.size()) - oldA;
}
}
while (!unknown.empty()) {
bool swapped = A.size() < B.size();
if (swapped) {
swap(A, B);
}
vector<int> que;
for (auto i : A) {
que.emplace_back(i);
que.emplace_back(*begin(unknown));
unknown.erase(begin(unknown));
if (unknown.empty()) {
break;
}
}
int q = use_machine(que);
ans += swapped ? ((q + 1) / 2) : (int(que.size()) / 2 - (q + 1) / 2);
if (q & 1) {
B.emplace_back(que.back());
} else {
A.emplace_back(que.back());
}
if (swapped) {
swap(A, B);
}
}
return ans;
};
return Solve(100);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
360 KB |
Output is correct |
7 |
Correct |
12 ms |
1256 KB |
Output is correct |
8 |
Correct |
14 ms |
1280 KB |
Output is correct |
9 |
Correct |
13 ms |
1280 KB |
Output is correct |
10 |
Correct |
13 ms |
1188 KB |
Output is correct |
11 |
Correct |
11 ms |
1280 KB |
Output is correct |
12 |
Correct |
12 ms |
1312 KB |
Output is correct |
13 |
Correct |
12 ms |
1308 KB |
Output is correct |
14 |
Correct |
6 ms |
848 KB |
Output is correct |
15 |
Correct |
14 ms |
1324 KB |
Output is correct |
16 |
Correct |
14 ms |
1304 KB |
Output is correct |
17 |
Correct |
6 ms |
768 KB |
Output is correct |
18 |
Correct |
12 ms |
1312 KB |
Output is correct |
19 |
Correct |
13 ms |
1280 KB |
Output is correct |
20 |
Correct |
14 ms |
1280 KB |
Output is correct |
21 |
Correct |
14 ms |
1408 KB |
Output is correct |
22 |
Correct |
14 ms |
1280 KB |
Output is correct |
23 |
Correct |
12 ms |
1308 KB |
Output is correct |
24 |
Correct |
7 ms |
848 KB |
Output is correct |
25 |
Correct |
13 ms |
1320 KB |
Output is correct |
26 |
Correct |
14 ms |
1280 KB |
Output is correct |
27 |
Correct |
14 ms |
1280 KB |
Output is correct |
28 |
Correct |
13 ms |
1312 KB |
Output is correct |
29 |
Correct |
13 ms |
1312 KB |
Output is correct |
30 |
Correct |
12 ms |
1312 KB |
Output is correct |
31 |
Correct |
13 ms |
1304 KB |
Output is correct |
32 |
Correct |
13 ms |
1280 KB |
Output is correct |
33 |
Correct |
12 ms |
1308 KB |
Output is correct |
34 |
Correct |
13 ms |
1280 KB |
Output is correct |
35 |
Correct |
12 ms |
1280 KB |
Output is correct |
36 |
Correct |
13 ms |
1280 KB |
Output is correct |
37 |
Correct |
12 ms |
1280 KB |
Output is correct |
38 |
Correct |
13 ms |
1280 KB |
Output is correct |
39 |
Correct |
14 ms |
1280 KB |
Output is correct |
40 |
Correct |
13 ms |
1280 KB |
Output is correct |
41 |
Correct |
14 ms |
1280 KB |
Output is correct |
42 |
Correct |
17 ms |
1280 KB |
Output is correct |
43 |
Correct |
11 ms |
1280 KB |
Output is correct |
44 |
Correct |
16 ms |
1308 KB |
Output is correct |
45 |
Correct |
12 ms |
1280 KB |
Output is correct |
46 |
Correct |
13 ms |
1400 KB |
Output is correct |
47 |
Correct |
10 ms |
1312 KB |
Output is correct |
48 |
Correct |
14 ms |
1316 KB |
Output is correct |
49 |
Correct |
12 ms |
1280 KB |
Output is correct |
50 |
Correct |
12 ms |
1280 KB |
Output is correct |
51 |
Correct |
17 ms |
1280 KB |
Output is correct |
52 |
Correct |
17 ms |
1280 KB |
Output is correct |
53 |
Correct |
13 ms |
1280 KB |
Output is correct |
54 |
Correct |
13 ms |
1280 KB |
Output is correct |
55 |
Correct |
10 ms |
1316 KB |
Output is correct |
56 |
Correct |
18 ms |
1280 KB |
Output is correct |
57 |
Correct |
19 ms |
1280 KB |
Output is correct |
58 |
Correct |
10 ms |
1312 KB |
Output is correct |
59 |
Correct |
12 ms |
1280 KB |
Output is correct |
60 |
Correct |
14 ms |
1280 KB |
Output is correct |
61 |
Correct |
12 ms |
1280 KB |
Output is correct |
62 |
Correct |
0 ms |
256 KB |
Output is correct |
63 |
Correct |
1 ms |
256 KB |
Output is correct |
64 |
Correct |
1 ms |
256 KB |
Output is correct |
65 |
Correct |
1 ms |
256 KB |
Output is correct |
66 |
Correct |
0 ms |
256 KB |
Output is correct |
67 |
Correct |
0 ms |
256 KB |
Output is correct |
68 |
Correct |
0 ms |
256 KB |
Output is correct |
69 |
Correct |
0 ms |
256 KB |
Output is correct |
70 |
Correct |
0 ms |
256 KB |
Output is correct |
71 |
Correct |
0 ms |
256 KB |
Output is correct |
72 |
Correct |
1 ms |
256 KB |
Output is correct |
73 |
Correct |
0 ms |
256 KB |
Output is correct |
74 |
Correct |
0 ms |
256 KB |
Output is correct |
75 |
Correct |
1 ms |
256 KB |
Output is correct |
76 |
Correct |
0 ms |
256 KB |
Output is correct |
77 |
Correct |
0 ms |
256 KB |
Output is correct |
78 |
Correct |
0 ms |
256 KB |
Output is correct |
79 |
Correct |
0 ms |
256 KB |
Output is correct |
80 |
Correct |
1 ms |
256 KB |
Output is correct |
81 |
Correct |
1 ms |
256 KB |
Output is correct |
82 |
Correct |
0 ms |
256 KB |
Output is correct |
83 |
Correct |
0 ms |
256 KB |
Output is correct |
84 |
Correct |
0 ms |
256 KB |
Output is correct |
85 |
Correct |
0 ms |
256 KB |
Output is correct |
86 |
Correct |
0 ms |
256 KB |
Output is correct |
87 |
Correct |
0 ms |
256 KB |
Output is correct |
88 |
Correct |
1 ms |
256 KB |
Output is correct |
89 |
Correct |
0 ms |
256 KB |
Output is correct |
90 |
Correct |
0 ms |
256 KB |
Output is correct |
91 |
Correct |
1 ms |
256 KB |
Output is correct |