#include "mushrooms.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) begin(a),end(a)
int U(vector<int> v){ return use_machine(v); }
const int B = 100;
vector<int> V[2];
int count_mushrooms(int n) {
int ans = 1, i=1, P;
if(n<=200){
for(int i = 1; i < n; i++)
ans+=!U({0,i});
return ans;
}
V[0].clear(), V[1].clear(); V[0].pb(0);
for(int j:{0,1}) V[U({0,i})].pb(i), i++;
P = sz(V[1])>sz(V[0]);
int x = U({V[P][0],i,V[P][1],i+1});
V[x%2?!P:P].pb(i+1); V[x>=2?!P:P].pb(i); i+=2;
while(i<n and sz(V[0])+sz(V[1])<2*B){
vector<int> v; v.clear();
P = sz(V[1])>sz(V[0]);
v.pb(V[P][0]), v.pb(i+1);
v.pb(V[P][1]), v.pb(i+2);
v.pb(V[P][2]), v.pb(i);
int x = U(v), c1=P, c2=P, c3=P, c4=P, c5=P;
if(x%2) c3^=1, x--;
if(x!=2){
if(x==4) c1^=1, c2^=1;
V[c1].pb(i+1); V[c2].pb(i+2); V[c3].pb(i); i+=3;
}
else{
if(sz(V[!P])>=2){
v.clear(); v.pb(V[!P][0]), v.pb(i+1), v.pb(V[!P][1]); v.pb(V[P][0]);
v.pb(i+2); v.pb(V[P][1]); v.pb(i+3); v.pb(V[P][2]); v.pb(i+4);
x = U(v)-1; c1 = !P;
if(x%2) c5^=1, x--;
if(x==2) c4^=1;
else if(x==4) c1^=1, c2^=1;
else if(x==6) c1^=1, c2^=1, c4^=1;
V[c1].pb(i+1); V[c2].pb(i+2); V[c3].pb(i); V[c4].pb(i+3); V[c5].pb(i+4); i+=5;
}
else{
if(U({0,i+1})) c1=1,c2=0;
else c1=0, c2=1;
V[c1].pb(i+1); V[c2].pb(i+2); V[c3].pb(i); i+=3;
}
}
}
ans=sz(V[0]);
while(i<n){
P = sz(V[1])>sz(V[0]);
vector<int> v; v.clear();
for(int j = 0; j < sz(V[P]) and i<n; j++)
v.pb(V[P][j]), v.pb(i), i++;
int x = U(v);
if(!P) ans+=sz(v)/2;
if(x%2) ans+=P?1:-1, V[P^1].pb(v.back());
else V[P].pb(v.back());
ans+=x/2*(P?1:-1);
if(i==n) break;
}
return ans;
}
Compilation message
mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:21:13: warning: unused variable 'j' [-Wunused-variable]
21 | for(int j:{0,1}) V[U({0,i})].pb(i), i++;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
3 ms |
344 KB |
Output is correct |
8 |
Correct |
2 ms |
452 KB |
Output is correct |
9 |
Correct |
3 ms |
344 KB |
Output is correct |
10 |
Correct |
3 ms |
344 KB |
Output is correct |
11 |
Correct |
3 ms |
460 KB |
Output is correct |
12 |
Correct |
3 ms |
344 KB |
Output is correct |
13 |
Correct |
4 ms |
344 KB |
Output is correct |
14 |
Correct |
2 ms |
344 KB |
Output is correct |
15 |
Correct |
3 ms |
344 KB |
Output is correct |
16 |
Correct |
5 ms |
344 KB |
Output is correct |
17 |
Correct |
2 ms |
344 KB |
Output is correct |
18 |
Correct |
3 ms |
452 KB |
Output is correct |
19 |
Correct |
3 ms |
344 KB |
Output is correct |
20 |
Correct |
3 ms |
344 KB |
Output is correct |
21 |
Correct |
3 ms |
344 KB |
Output is correct |
22 |
Correct |
3 ms |
472 KB |
Output is correct |
23 |
Correct |
2 ms |
344 KB |
Output is correct |
24 |
Correct |
2 ms |
344 KB |
Output is correct |
25 |
Correct |
3 ms |
476 KB |
Output is correct |
26 |
Correct |
3 ms |
448 KB |
Output is correct |
27 |
Correct |
3 ms |
344 KB |
Output is correct |
28 |
Correct |
3 ms |
344 KB |
Output is correct |
29 |
Correct |
3 ms |
344 KB |
Output is correct |
30 |
Correct |
3 ms |
472 KB |
Output is correct |
31 |
Correct |
5 ms |
476 KB |
Output is correct |
32 |
Correct |
3 ms |
344 KB |
Output is correct |
33 |
Correct |
3 ms |
444 KB |
Output is correct |
34 |
Correct |
3 ms |
344 KB |
Output is correct |
35 |
Correct |
3 ms |
452 KB |
Output is correct |
36 |
Correct |
3 ms |
460 KB |
Output is correct |
37 |
Correct |
3 ms |
344 KB |
Output is correct |
38 |
Correct |
3 ms |
344 KB |
Output is correct |
39 |
Correct |
3 ms |
344 KB |
Output is correct |
40 |
Correct |
3 ms |
344 KB |
Output is correct |
41 |
Correct |
3 ms |
340 KB |
Output is correct |
42 |
Correct |
3 ms |
344 KB |
Output is correct |
43 |
Correct |
3 ms |
344 KB |
Output is correct |
44 |
Correct |
3 ms |
344 KB |
Output is correct |
45 |
Correct |
3 ms |
344 KB |
Output is correct |
46 |
Correct |
3 ms |
440 KB |
Output is correct |
47 |
Correct |
3 ms |
344 KB |
Output is correct |
48 |
Correct |
4 ms |
464 KB |
Output is correct |
49 |
Correct |
3 ms |
468 KB |
Output is correct |
50 |
Correct |
3 ms |
344 KB |
Output is correct |
51 |
Correct |
3 ms |
344 KB |
Output is correct |
52 |
Correct |
3 ms |
344 KB |
Output is correct |
53 |
Correct |
3 ms |
468 KB |
Output is correct |
54 |
Correct |
3 ms |
344 KB |
Output is correct |
55 |
Correct |
3 ms |
344 KB |
Output is correct |
56 |
Correct |
4 ms |
344 KB |
Output is correct |
57 |
Correct |
3 ms |
344 KB |
Output is correct |
58 |
Correct |
3 ms |
444 KB |
Output is correct |
59 |
Correct |
3 ms |
344 KB |
Output is correct |
60 |
Correct |
3 ms |
344 KB |
Output is correct |
61 |
Correct |
3 ms |
452 KB |
Output is correct |
62 |
Correct |
0 ms |
344 KB |
Output is correct |
63 |
Correct |
0 ms |
344 KB |
Output is correct |
64 |
Correct |
0 ms |
344 KB |
Output is correct |
65 |
Correct |
1 ms |
344 KB |
Output is correct |
66 |
Correct |
0 ms |
432 KB |
Output is correct |
67 |
Correct |
1 ms |
344 KB |
Output is correct |
68 |
Correct |
0 ms |
344 KB |
Output is correct |
69 |
Correct |
0 ms |
344 KB |
Output is correct |
70 |
Correct |
0 ms |
344 KB |
Output is correct |
71 |
Correct |
0 ms |
344 KB |
Output is correct |
72 |
Correct |
0 ms |
344 KB |
Output is correct |
73 |
Correct |
0 ms |
344 KB |
Output is correct |
74 |
Correct |
0 ms |
344 KB |
Output is correct |
75 |
Correct |
0 ms |
344 KB |
Output is correct |
76 |
Correct |
0 ms |
344 KB |
Output is correct |
77 |
Correct |
0 ms |
344 KB |
Output is correct |
78 |
Correct |
0 ms |
344 KB |
Output is correct |
79 |
Correct |
0 ms |
344 KB |
Output is correct |
80 |
Correct |
0 ms |
344 KB |
Output is correct |
81 |
Correct |
0 ms |
344 KB |
Output is correct |
82 |
Correct |
0 ms |
344 KB |
Output is correct |
83 |
Correct |
0 ms |
344 KB |
Output is correct |
84 |
Correct |
0 ms |
344 KB |
Output is correct |
85 |
Correct |
0 ms |
344 KB |
Output is correct |
86 |
Correct |
0 ms |
344 KB |
Output is correct |
87 |
Correct |
0 ms |
344 KB |
Output is correct |
88 |
Correct |
0 ms |
344 KB |
Output is correct |
89 |
Correct |
0 ms |
344 KB |
Output is correct |
90 |
Correct |
0 ms |
344 KB |
Output is correct |
91 |
Correct |
0 ms |
344 KB |
Output is correct |