#include "mushrooms.h"
#include<bits/stdc++.h>
using namespace std;
const int CUT=45;
int count_mushrooms(int n) {
if(n==2)return 2-use_machine({0,1});
vector<int> c(n);
c[0]=0;
vector<int> pos[2];
for(int i=1;i<=2;i++)c[i]=use_machine({0,i});
for(int i=0;i<=2;i++)pos[c[i]].emplace_back(i);
int id=pos[1].size()>pos[0].size();
int front=3;
auto find2=[&](int idx){
int tmp=use_machine({idx,pos[id][0],idx+1,pos[id][1]});
c[idx]=tmp&1^id;
c[idx+1]=tmp>>1^id;
};
for(int i=0;i<1&&front+1<n;i++,front+=2){
find2(front);
for(int j=0;j<2;j++)pos[c[front+j]].emplace_back(front+j);
}
for(int i=0;i<CUT&&front+4<n;i++,front+=5){
id=pos[1].size()>pos[0].size();
int tmp=use_machine({front,pos[id][0],front+1,pos[id][1],front+2,pos[id][2]});
c[front]=tmp&1^id;
if((tmp>>1)!=1){
c[front+1]=c[front+2]=tmp>>2^id;
find2(front+3);
}else{
if(pos[id^1].size()>1){
tmp=use_machine({front+3,pos[id][0],front+4,pos[id][1],front+1,pos[id][2],pos[id^1][0],front+2,pos[id^1][1]})-1;
c[front+3]=tmp&1^id;
c[front+4]=tmp>>1&1^id;
c[front+1]=tmp>>2^id;
c[front+2]=c[front+1]^1;
}else{
find2(front+1);
find2(front+3);
}
}
for(int j=0;j<5;j++)pos[c[front+j]].emplace_back(front+j);
}
int last=n;
int sum=0;
for(int i=front;i<last;i++){
id=pos[1].size()>pos[0].size();
vector<int> res;
int cnt=0;
for(int j=0;j<pos[id].size();j++){
if(j==0){
res.emplace_back(i);
}else{
res.emplace_back(--last);
cnt++;
}
res.emplace_back(pos[id][j]);
if(last==i+1)break;
}
int tmp=use_machine(res);
c[i]=tmp&1^id;
pos[c[i]].emplace_back(i);
if(id){
sum+=tmp>>1;
}else{
sum+=cnt-(tmp>>1);
}
}
for(int i=0;i<last;i++)sum+=c[i]==0;
return sum;
}
Compilation message
mushrooms.cpp: In lambda function:
mushrooms.cpp:19:13: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
19 | c[idx]=tmp&1^id;
| ~~~^~
mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:29:15: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
29 | c[front]=tmp&1^id;
| ~~~^~
mushrooms.cpp:36:19: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
36 | c[front+3]=tmp&1^id;
| ~~~^~
mushrooms.cpp:37:22: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
37 | c[front+4]=tmp>>1&1^id;
| ~~~~~~^~
mushrooms.cpp:53:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for(int j=0;j<pos[id].size();j++){
| ~^~~~~~~~~~~~~~~
mushrooms.cpp:64:11: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
64 | c[i]=tmp&1^id;
| ~~~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
316 KB |
Output is correct |
7 |
Correct |
4 ms |
336 KB |
Output is correct |
8 |
Correct |
4 ms |
336 KB |
Output is correct |
9 |
Correct |
4 ms |
396 KB |
Output is correct |
10 |
Correct |
7 ms |
392 KB |
Output is correct |
11 |
Correct |
5 ms |
392 KB |
Output is correct |
12 |
Correct |
5 ms |
396 KB |
Output is correct |
13 |
Correct |
5 ms |
396 KB |
Output is correct |
14 |
Correct |
3 ms |
352 KB |
Output is correct |
15 |
Correct |
5 ms |
336 KB |
Output is correct |
16 |
Correct |
5 ms |
392 KB |
Output is correct |
17 |
Correct |
2 ms |
348 KB |
Output is correct |
18 |
Correct |
4 ms |
388 KB |
Output is correct |
19 |
Correct |
4 ms |
336 KB |
Output is correct |
20 |
Correct |
4 ms |
384 KB |
Output is correct |
21 |
Correct |
4 ms |
392 KB |
Output is correct |
22 |
Correct |
5 ms |
392 KB |
Output is correct |
23 |
Correct |
5 ms |
388 KB |
Output is correct |
24 |
Correct |
3 ms |
336 KB |
Output is correct |
25 |
Correct |
5 ms |
336 KB |
Output is correct |
26 |
Correct |
5 ms |
336 KB |
Output is correct |
27 |
Correct |
5 ms |
336 KB |
Output is correct |
28 |
Correct |
5 ms |
336 KB |
Output is correct |
29 |
Correct |
5 ms |
336 KB |
Output is correct |
30 |
Correct |
5 ms |
336 KB |
Output is correct |
31 |
Correct |
7 ms |
336 KB |
Output is correct |
32 |
Correct |
7 ms |
388 KB |
Output is correct |
33 |
Correct |
5 ms |
396 KB |
Output is correct |
34 |
Correct |
7 ms |
464 KB |
Output is correct |
35 |
Correct |
5 ms |
336 KB |
Output is correct |
36 |
Correct |
5 ms |
396 KB |
Output is correct |
37 |
Correct |
5 ms |
400 KB |
Output is correct |
38 |
Correct |
5 ms |
400 KB |
Output is correct |
39 |
Correct |
5 ms |
336 KB |
Output is correct |
40 |
Correct |
5 ms |
396 KB |
Output is correct |
41 |
Correct |
5 ms |
336 KB |
Output is correct |
42 |
Correct |
7 ms |
336 KB |
Output is correct |
43 |
Correct |
5 ms |
336 KB |
Output is correct |
44 |
Correct |
5 ms |
404 KB |
Output is correct |
45 |
Correct |
5 ms |
388 KB |
Output is correct |
46 |
Correct |
5 ms |
400 KB |
Output is correct |
47 |
Correct |
5 ms |
400 KB |
Output is correct |
48 |
Correct |
5 ms |
400 KB |
Output is correct |
49 |
Correct |
5 ms |
344 KB |
Output is correct |
50 |
Correct |
5 ms |
336 KB |
Output is correct |
51 |
Correct |
5 ms |
404 KB |
Output is correct |
52 |
Correct |
6 ms |
388 KB |
Output is correct |
53 |
Correct |
5 ms |
396 KB |
Output is correct |
54 |
Correct |
6 ms |
396 KB |
Output is correct |
55 |
Correct |
5 ms |
336 KB |
Output is correct |
56 |
Correct |
6 ms |
380 KB |
Output is correct |
57 |
Correct |
4 ms |
400 KB |
Output is correct |
58 |
Correct |
6 ms |
388 KB |
Output is correct |
59 |
Correct |
6 ms |
400 KB |
Output is correct |
60 |
Correct |
5 ms |
428 KB |
Output is correct |
61 |
Correct |
4 ms |
400 KB |
Output is correct |
62 |
Correct |
0 ms |
208 KB |
Output is correct |
63 |
Correct |
0 ms |
320 KB |
Output is correct |
64 |
Correct |
0 ms |
208 KB |
Output is correct |
65 |
Correct |
0 ms |
208 KB |
Output is correct |
66 |
Correct |
0 ms |
208 KB |
Output is correct |
67 |
Correct |
0 ms |
208 KB |
Output is correct |
68 |
Correct |
0 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 |
0 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 |
0 ms |
208 KB |
Output is correct |
76 |
Correct |
0 ms |
208 KB |
Output is correct |
77 |
Correct |
0 ms |
208 KB |
Output is correct |
78 |
Correct |
0 ms |
208 KB |
Output is correct |
79 |
Correct |
0 ms |
208 KB |
Output is correct |
80 |
Correct |
0 ms |
208 KB |
Output is correct |
81 |
Correct |
0 ms |
208 KB |
Output is correct |
82 |
Correct |
0 ms |
208 KB |
Output is correct |
83 |
Correct |
0 ms |
208 KB |
Output is correct |
84 |
Correct |
1 ms |
208 KB |
Output is correct |
85 |
Correct |
0 ms |
208 KB |
Output is correct |
86 |
Correct |
1 ms |
208 KB |
Output is correct |
87 |
Correct |
0 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 |