#include "mushrooms.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> a, b;
int cnt = 106;
int count_mushrooms(int n) {
a.push_back(0);
if(n < 2*cnt+5) {
for(int i = 1; i < n; i++)
use_machine({0, i}) ? b.push_back(i) : a.push_back(i);
return a.size();
}
use_machine({0, 1}) ? b.push_back(1) : a.push_back(1);
use_machine({0, 2}) ? b.push_back(2) : a.push_back(2);
if(a.size() > 1) {
int x = use_machine({a[0], 3, a[1], 4});
(x&1) ? b.push_back(4) : a.push_back(4);
(x&2) ? b.push_back(3) : a.push_back(3);
}
else {
int x = use_machine({b[0], 3, b[1], 4});
(x&1) ? a.push_back(4) : b.push_back(4);
(x&2) ? a.push_back(3) : b.push_back(3);
}
int idx = 5; bool flag = false;
if(a.size() < 3) flag = true;
if(flag) swap(a, b);
while(idx <= 2*cnt) {
int x = use_machine({a[0], idx, a[1], idx+1, a[2], idx+2});
(x&1) ? b.push_back(idx+2) : a.push_back(idx+2);
if(x/2 == 0) {
a.push_back(idx);
a.push_back(idx+1);
idx += 3;
}
else if(x/2 == 2) {
b.push_back(idx);
b.push_back(idx+1);
idx += 3;
}
else if(b.size() > 1) {
int x = use_machine({b[0], idx, b[1], a[0], idx+1, a[1], idx+3, a[2], idx+4})-1;
(x&1) ? b.push_back(idx+4) : a.push_back(idx+4);
(x&2) ? b.push_back(idx+3) : a.push_back(idx+3);
(x&4) ? b.push_back(idx+1) : a.push_back(idx+1);
(x&4) ? a.push_back(idx) : b.push_back(idx);
idx += 5;
}
else {
int x = use_machine({a[0], idx, a[1], idx+3});
(x&1) ? b.push_back(idx+3) : a.push_back(idx+3);
(x&2) ? b.push_back(idx) : a.push_back(idx);
(x&2) ? a.push_back(idx+1) : b.push_back(idx+1);
idx += 4;
}
}
if(flag) swap(a, b);
if(a.size() + b.size() == n) return a.size();
std::vector<int> m;
int res = a.size();
while(idx < n) {
if(a.size() > b.size()) {
int z;
m.clear();
for(int i = 0; i < a.size(); i++) {
if(idx < n) {
if(i == 0) z = idx;
m.push_back(idx++);
}
m.push_back(a[i]);
}
int x = use_machine(m);
res += (int)m.size() - (int)a.size() - (x+1)/2;
(x&1) ? b.push_back(z) : a.push_back(z);
}
else {
int z;
m.clear();
for(int i = 0; i < b.size(); i++) {
if(idx < n) {
if(i == 0) z = idx;
m.push_back(idx++);
}
m.push_back(b[i]);
}
int x = use_machine(m);
res += (x+1)/2;
(x&1) ? a.push_back(z) : b.push_back(z);
}
}
return res;
}
Compilation message
mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:67:25: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
67 | if(a.size() + b.size() == n) return a.size();
| ~~~~~~~~~~~~~~~~~~~~^~~~
mushrooms.cpp:75:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
75 | for(int i = 0; i < a.size(); i++) {
| ~~^~~~~~~~~~
mushrooms.cpp:90:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
90 | for(int i = 0; i < b.size(); i++) {
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
308 KB |
Output is correct |
6 |
Correct |
3 ms |
208 KB |
Output is correct |
7 |
Correct |
6 ms |
208 KB |
Output is correct |
8 |
Correct |
6 ms |
316 KB |
Output is correct |
9 |
Correct |
5 ms |
312 KB |
Output is correct |
10 |
Correct |
5 ms |
300 KB |
Output is correct |
11 |
Correct |
8 ms |
208 KB |
Output is correct |
12 |
Correct |
6 ms |
208 KB |
Output is correct |
13 |
Correct |
8 ms |
312 KB |
Output is correct |
14 |
Correct |
4 ms |
320 KB |
Output is correct |
15 |
Correct |
7 ms |
308 KB |
Output is correct |
16 |
Correct |
7 ms |
316 KB |
Output is correct |
17 |
Correct |
5 ms |
208 KB |
Output is correct |
18 |
Correct |
6 ms |
316 KB |
Output is correct |
19 |
Correct |
8 ms |
312 KB |
Output is correct |
20 |
Correct |
6 ms |
208 KB |
Output is correct |
21 |
Correct |
13 ms |
304 KB |
Output is correct |
22 |
Correct |
6 ms |
328 KB |
Output is correct |
23 |
Correct |
7 ms |
208 KB |
Output is correct |
24 |
Correct |
5 ms |
316 KB |
Output is correct |
25 |
Correct |
7 ms |
320 KB |
Output is correct |
26 |
Correct |
7 ms |
208 KB |
Output is correct |
27 |
Correct |
9 ms |
320 KB |
Output is correct |
28 |
Correct |
6 ms |
208 KB |
Output is correct |
29 |
Correct |
5 ms |
316 KB |
Output is correct |
30 |
Correct |
6 ms |
320 KB |
Output is correct |
31 |
Correct |
7 ms |
316 KB |
Output is correct |
32 |
Correct |
6 ms |
208 KB |
Output is correct |
33 |
Correct |
7 ms |
320 KB |
Output is correct |
34 |
Correct |
9 ms |
320 KB |
Output is correct |
35 |
Correct |
12 ms |
208 KB |
Output is correct |
36 |
Correct |
8 ms |
312 KB |
Output is correct |
37 |
Correct |
6 ms |
320 KB |
Output is correct |
38 |
Correct |
6 ms |
208 KB |
Output is correct |
39 |
Correct |
6 ms |
308 KB |
Output is correct |
40 |
Correct |
8 ms |
312 KB |
Output is correct |
41 |
Correct |
7 ms |
312 KB |
Output is correct |
42 |
Correct |
7 ms |
320 KB |
Output is correct |
43 |
Correct |
8 ms |
208 KB |
Output is correct |
44 |
Correct |
7 ms |
208 KB |
Output is correct |
45 |
Correct |
6 ms |
312 KB |
Output is correct |
46 |
Correct |
6 ms |
208 KB |
Output is correct |
47 |
Correct |
7 ms |
316 KB |
Output is correct |
48 |
Correct |
9 ms |
320 KB |
Output is correct |
49 |
Correct |
10 ms |
208 KB |
Output is correct |
50 |
Correct |
8 ms |
316 KB |
Output is correct |
51 |
Correct |
8 ms |
208 KB |
Output is correct |
52 |
Correct |
8 ms |
304 KB |
Output is correct |
53 |
Correct |
8 ms |
316 KB |
Output is correct |
54 |
Correct |
6 ms |
208 KB |
Output is correct |
55 |
Correct |
5 ms |
320 KB |
Output is correct |
56 |
Correct |
8 ms |
308 KB |
Output is correct |
57 |
Correct |
5 ms |
208 KB |
Output is correct |
58 |
Correct |
6 ms |
208 KB |
Output is correct |
59 |
Correct |
9 ms |
316 KB |
Output is correct |
60 |
Correct |
8 ms |
312 KB |
Output is correct |
61 |
Correct |
6 ms |
208 KB |
Output is correct |
62 |
Correct |
1 ms |
208 KB |
Output is correct |
63 |
Correct |
0 ms |
208 KB |
Output is correct |
64 |
Correct |
1 ms |
208 KB |
Output is correct |
65 |
Correct |
1 ms |
208 KB |
Output is correct |
66 |
Correct |
1 ms |
208 KB |
Output is correct |
67 |
Correct |
1 ms |
208 KB |
Output is correct |
68 |
Correct |
1 ms |
208 KB |
Output is correct |
69 |
Correct |
0 ms |
208 KB |
Output is correct |
70 |
Correct |
0 ms |
208 KB |
Output is correct |
71 |
Correct |
1 ms |
208 KB |
Output is correct |
72 |
Correct |
0 ms |
208 KB |
Output is correct |
73 |
Correct |
0 ms |
208 KB |
Output is correct |
74 |
Correct |
0 ms |
208 KB |
Output is correct |
75 |
Correct |
1 ms |
208 KB |
Output is correct |
76 |
Correct |
1 ms |
208 KB |
Output is correct |
77 |
Correct |
1 ms |
208 KB |
Output is correct |
78 |
Correct |
0 ms |
208 KB |
Output is correct |
79 |
Correct |
1 ms |
208 KB |
Output is correct |
80 |
Correct |
1 ms |
208 KB |
Output is correct |
81 |
Correct |
1 ms |
208 KB |
Output is correct |
82 |
Correct |
1 ms |
208 KB |
Output is correct |
83 |
Correct |
0 ms |
208 KB |
Output is correct |
84 |
Correct |
0 ms |
208 KB |
Output is correct |
85 |
Correct |
1 ms |
292 KB |
Output is correct |
86 |
Correct |
0 ms |
208 KB |
Output is correct |
87 |
Correct |
1 ms |
208 KB |
Output is correct |
88 |
Correct |
0 ms |
208 KB |
Output is correct |
89 |
Correct |
0 ms |
208 KB |
Output is correct |
90 |
Correct |
0 ms |
208 KB |
Output is correct |
91 |
Correct |
0 ms |
208 KB |
Output is correct |