#include <bits/stdc++.h>
#include "mushrooms.h"
using namespace std;
int count_mushrooms(int n) {
vector<int> s[8], q1 = {0, 1, 5, 2, 6, 3, 7, 4}, q2[8];
map<int, int> mp[8];
for(int mask = 0; mask < 32; mask++) {
vector<int> a(9);
a[8] = 1;
for(int i = 0; i < 5; i++)
a[i] = mask >> i & 1;
int sum = 0;
for(int i = 1; i < 8; i++)
sum += a[q1[i - 1]] ^ a[q1[i]];
s[sum].push_back(mask);
}
for(int i = 0; i < 8; i++){
vector<int> p(9);
iota(p.begin(), p.end(), 0);
bool ok = 0;
do {
map<int, int> sums;
for(int mask : s[i]) {
vector<int> a(9, 0);
a[8] = 1;
for(int i = 0; i < 5; i++)
a[i] = mask >> i & 1;
int sum = 0;
for(int i = 1; i < 9; i++)
sum += a[p[i - 1]] ^ a[p[i]];
sums[sum] = mask;
}
if (s[i].size() == sums.size()) {
ok = 1;
q2[i] = p;
mp[i] = sums;
break;
}
} while (next_permutation(p.begin(), p.end()));
assert(ok);
}
vector<int> type[2];
type[0].push_back(0);
int flag = 0, cur = 1, k = 220, cnt[2] = {0, 0};
while (cur < n) {
if (type[0].size() < type[1].size()) {
flag ^= 1;
swap(type[0], type[1]);
swap(cnt[0], cnt[1]);
}
if ((int) cur < k) {
int num = min(5, n - cur);
if (num < 5 || (int) type[0].size() < 3 || (int) type[1].size() < 1) {
num = min(num, min(2, (int) type[0].size()));
vector<int> a;
for(int i = 0; i < num; i++) {
a.push_back(cur + i);
a.push_back(type[0][i]);
}
int x = use_machine(a);
for(int i = 0; i < num; i++)
type[(x >> i) & 1].push_back(cur + i);
cur += num;
} else {
vector<int> pos;
for(int i = 0; i < 5; i++)
pos.push_back(cur + i);
for(int i = 0; i < 3; i++)
pos.push_back(type[0][i]);
pos.push_back(type[1][0]);
vector<int> a;
for(int x : q1)
a.push_back(pos[x]);
int res = use_machine(a);
a.clear();
for(int x : q2[res])
a.push_back(pos[x]);
int mask = mp[res][use_machine(a)];
for(int i = 0; i < 5; i++)
type[(mask >> i) & 1].push_back(cur + i);
cur += num;
}
} else {
int num = min(n - cur, (int) type[0].size());
vector<int> a;
for(int i = 0; i < num; i++) {
a.push_back(cur + i);
a.push_back(type[0][i]);
}
int x = use_machine(a);
type[x & 1].push_back(cur);
cnt[1] += x / 2;
cnt[0] += (num - 1) - x / 2;
cur += num;
}
}
if (flag) {
flag ^= 1;
swap(type[0], type[1]);
swap(cnt[0], cnt[1]);
}
return cnt[0] + type[0].size();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
200 KB |
Output is correct |
2 |
Correct |
44 ms |
200 KB |
Output is correct |
3 |
Correct |
43 ms |
200 KB |
Output is correct |
4 |
Correct |
45 ms |
200 KB |
Output is correct |
5 |
Correct |
49 ms |
324 KB |
Output is correct |
6 |
Correct |
47 ms |
288 KB |
Output is correct |
7 |
Correct |
52 ms |
268 KB |
Output is correct |
8 |
Correct |
50 ms |
284 KB |
Output is correct |
9 |
Correct |
50 ms |
284 KB |
Output is correct |
10 |
Correct |
49 ms |
268 KB |
Output is correct |
11 |
Correct |
50 ms |
268 KB |
Output is correct |
12 |
Correct |
53 ms |
284 KB |
Output is correct |
13 |
Correct |
51 ms |
200 KB |
Output is correct |
14 |
Correct |
47 ms |
280 KB |
Output is correct |
15 |
Correct |
50 ms |
200 KB |
Output is correct |
16 |
Correct |
53 ms |
280 KB |
Output is correct |
17 |
Correct |
47 ms |
200 KB |
Output is correct |
18 |
Correct |
51 ms |
284 KB |
Output is correct |
19 |
Correct |
51 ms |
284 KB |
Output is correct |
20 |
Correct |
50 ms |
320 KB |
Output is correct |
21 |
Correct |
51 ms |
200 KB |
Output is correct |
22 |
Correct |
52 ms |
288 KB |
Output is correct |
23 |
Correct |
49 ms |
284 KB |
Output is correct |
24 |
Correct |
49 ms |
320 KB |
Output is correct |
25 |
Correct |
50 ms |
280 KB |
Output is correct |
26 |
Correct |
55 ms |
280 KB |
Output is correct |
27 |
Correct |
50 ms |
288 KB |
Output is correct |
28 |
Correct |
48 ms |
408 KB |
Output is correct |
29 |
Correct |
53 ms |
200 KB |
Output is correct |
30 |
Correct |
55 ms |
268 KB |
Output is correct |
31 |
Correct |
63 ms |
288 KB |
Output is correct |
32 |
Correct |
50 ms |
280 KB |
Output is correct |
33 |
Correct |
53 ms |
288 KB |
Output is correct |
34 |
Correct |
53 ms |
280 KB |
Output is correct |
35 |
Correct |
53 ms |
448 KB |
Output is correct |
36 |
Correct |
63 ms |
296 KB |
Output is correct |
37 |
Correct |
56 ms |
320 KB |
Output is correct |
38 |
Correct |
51 ms |
280 KB |
Output is correct |
39 |
Correct |
50 ms |
300 KB |
Output is correct |
40 |
Correct |
51 ms |
284 KB |
Output is correct |
41 |
Correct |
57 ms |
268 KB |
Output is correct |
42 |
Correct |
50 ms |
284 KB |
Output is correct |
43 |
Correct |
50 ms |
288 KB |
Output is correct |
44 |
Correct |
51 ms |
280 KB |
Output is correct |
45 |
Correct |
57 ms |
268 KB |
Output is correct |
46 |
Correct |
51 ms |
284 KB |
Output is correct |
47 |
Correct |
50 ms |
280 KB |
Output is correct |
48 |
Correct |
49 ms |
284 KB |
Output is correct |
49 |
Correct |
50 ms |
200 KB |
Output is correct |
50 |
Correct |
54 ms |
200 KB |
Output is correct |
51 |
Correct |
52 ms |
284 KB |
Output is correct |
52 |
Correct |
48 ms |
292 KB |
Output is correct |
53 |
Correct |
53 ms |
200 KB |
Output is correct |
54 |
Correct |
50 ms |
320 KB |
Output is correct |
55 |
Correct |
51 ms |
200 KB |
Output is correct |
56 |
Correct |
58 ms |
272 KB |
Output is correct |
57 |
Correct |
50 ms |
200 KB |
Output is correct |
58 |
Correct |
52 ms |
284 KB |
Output is correct |
59 |
Correct |
52 ms |
200 KB |
Output is correct |
60 |
Correct |
55 ms |
284 KB |
Output is correct |
61 |
Correct |
64 ms |
200 KB |
Output is correct |
62 |
Correct |
43 ms |
272 KB |
Output is correct |
63 |
Correct |
43 ms |
200 KB |
Output is correct |
64 |
Correct |
43 ms |
200 KB |
Output is correct |
65 |
Correct |
44 ms |
280 KB |
Output is correct |
66 |
Correct |
43 ms |
200 KB |
Output is correct |
67 |
Correct |
51 ms |
272 KB |
Output is correct |
68 |
Correct |
56 ms |
200 KB |
Output is correct |
69 |
Correct |
55 ms |
200 KB |
Output is correct |
70 |
Correct |
43 ms |
284 KB |
Output is correct |
71 |
Correct |
46 ms |
200 KB |
Output is correct |
72 |
Correct |
43 ms |
272 KB |
Output is correct |
73 |
Correct |
45 ms |
268 KB |
Output is correct |
74 |
Correct |
44 ms |
200 KB |
Output is correct |
75 |
Correct |
43 ms |
200 KB |
Output is correct |
76 |
Correct |
43 ms |
200 KB |
Output is correct |
77 |
Correct |
57 ms |
200 KB |
Output is correct |
78 |
Correct |
46 ms |
280 KB |
Output is correct |
79 |
Correct |
44 ms |
200 KB |
Output is correct |
80 |
Correct |
44 ms |
200 KB |
Output is correct |
81 |
Correct |
43 ms |
200 KB |
Output is correct |
82 |
Correct |
44 ms |
272 KB |
Output is correct |
83 |
Correct |
45 ms |
276 KB |
Output is correct |
84 |
Correct |
44 ms |
200 KB |
Output is correct |
85 |
Correct |
43 ms |
200 KB |
Output is correct |
86 |
Correct |
44 ms |
200 KB |
Output is correct |
87 |
Correct |
43 ms |
276 KB |
Output is correct |
88 |
Correct |
43 ms |
200 KB |
Output is correct |
89 |
Correct |
53 ms |
200 KB |
Output is correct |
90 |
Correct |
44 ms |
272 KB |
Output is correct |
91 |
Correct |
43 ms |
272 KB |
Output is correct |