#include "mushrooms.h"
#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,int(v.size())) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<x.F<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first
const int N=20202,M=604,inf=1e9;
int n,ans,cnt,mark[N],dp[N][M];
vector<int> A,B;
int calc(int n,int x){
if(n<=0) return 0;
if(x>=M) return N;
if(dp[n][x]!=-1) return dp[n][x];
return dp[n][x]=min(calc(n-2,x+2),calc(n-(x+1)/2,x+1))+1;
}
int get(int l,int r){
vector<int> vec;
f(i,l,r+1) vec.pb(i);
return use_machine(vec);
}
int get(vector<int> vec){
cnt++;
if(vec.size()<=A.size()){
vector<int> res;
f(i,0,int(vec.size())) res.pb(vec[i]),res.pb(A[i]);
int prt=use_machine(res);
if(prt&1) B.pb(vec[0]);
else A.pb(vec[0]);
prt=(prt+1)/2;
return int(vec.size())-prt;
}
else{
vector<int> res;
f(i,0,int(vec.size())) res.pb(vec[i]),res.pb(B[i]);
int prt=use_machine(res);
if(prt&1) A.pb(vec[0]);
else B.pb(vec[0]);
prt=(prt+1)/2;
return prt;
}
}
int count_mushrooms(int _n) {
f(i,0,N) f(j,0,M) dp[i][j]=-1;
n=_n;
mark[0]=1;
A.pb(0);
/*
int now=use_machine({0,1});
if(now==0){
A.pb(1);
}
else{
B.pb(1);
}
int l=1,r=n;
while(l+1<r){
int mid=(l+r)>>1;;
if(now==get(0,mid)) l=mid;
else r=mid;
}
if(r==n && now==0){
return n;
}
if(r==n && now==1){
mark[2]=1;
B.pb(2);
}
else{
if(get(0,r)&1){
B.pb(r);
}
else{
A.pb(r);
}
}
mark[r]=1;*/
ans=A.size();
vector<int> al,vec;
f(i,0,n) if(!mark[i]) al.pb(i);
while(al.size()){
int i=al.back();
al.pop_back();
vec.pb(i);
int m=int(al.size())+2,sz=A.size()+B.size();
if(min(sz(A),sz(B))>0 && max(sz(A),sz(B))>1 && vec.size()==2 && calc(m-2,sz+2)<calc(m-(sz+1)/2,sz+1)){
//cout<<"calc = "<<calc(n-sz(vec)-sz(al),sz(A)+sz(B))<<endl;
if(A.size()>=2 && B.size()>=1){
vector<int> res;
res.pb(A[0]);
res.pb(vec[0]);
res.pb(A[1]);
res.pb(B[0]);
res.pb(vec[1]);
int prt=use_machine(res)-1; cnt++;
if(prt&2){
B.pb(vec[0]);
}
else{
ans++;
A.pb(vec[0]);
}
if(prt&1){
ans++;
A.pb(vec[1]);
}
else{
B.pb(vec[1]);
}
}
else{
vector<int> res;
res.pb(B[0]);
res.pb(vec[0]);
res.pb(B[1]);
res.pb(A[0]);
res.pb(vec[1]);
int prt=use_machine(res)-1; cnt++;
if(prt&2){
ans++;
A.pb(vec[0]);
}
else{
B.pb(vec[0]);
}
if(prt&1){
B.pb(vec[1]);
}
else{
ans++;
A.pb(vec[1]);
}
}
vec.clear();
}
else if(int(vec.size())>=max(int(A.size()),int(B.size()))){
ans+=get(vec);
vec.clear();
}
}
if(vec.size()){
ans+=get(vec);
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
48024 KB |
Output is correct |
2 |
Correct |
22 ms |
47976 KB |
Output is correct |
3 |
Correct |
22 ms |
48060 KB |
Output is correct |
4 |
Correct |
21 ms |
48016 KB |
Output is correct |
5 |
Correct |
21 ms |
47948 KB |
Output is correct |
6 |
Correct |
40 ms |
47984 KB |
Output is correct |
7 |
Correct |
30 ms |
48164 KB |
Output is correct |
8 |
Correct |
142 ms |
48200 KB |
Output is correct |
9 |
Correct |
139 ms |
48228 KB |
Output is correct |
10 |
Correct |
139 ms |
48280 KB |
Output is correct |
11 |
Partially correct |
178 ms |
48268 KB |
Output is partially correct |
12 |
Correct |
164 ms |
48164 KB |
Output is correct |
13 |
Correct |
139 ms |
48208 KB |
Output is correct |
14 |
Correct |
79 ms |
48164 KB |
Output is correct |
15 |
Partially correct |
160 ms |
48208 KB |
Output is partially correct |
16 |
Partially correct |
166 ms |
48284 KB |
Output is partially correct |
17 |
Correct |
80 ms |
48164 KB |
Output is correct |
18 |
Correct |
128 ms |
48208 KB |
Output is correct |
19 |
Partially correct |
127 ms |
48200 KB |
Output is partially correct |
20 |
Correct |
131 ms |
48236 KB |
Output is correct |
21 |
Correct |
133 ms |
48180 KB |
Output is correct |
22 |
Partially correct |
127 ms |
48256 KB |
Output is partially correct |
23 |
Correct |
141 ms |
48236 KB |
Output is correct |
24 |
Correct |
85 ms |
48068 KB |
Output is correct |
25 |
Partially correct |
148 ms |
48208 KB |
Output is partially correct |
26 |
Partially correct |
173 ms |
48268 KB |
Output is partially correct |
27 |
Partially correct |
157 ms |
48208 KB |
Output is partially correct |
28 |
Partially correct |
167 ms |
48232 KB |
Output is partially correct |
29 |
Partially correct |
145 ms |
48208 KB |
Output is partially correct |
30 |
Partially correct |
130 ms |
48208 KB |
Output is partially correct |
31 |
Partially correct |
164 ms |
48252 KB |
Output is partially correct |
32 |
Partially correct |
137 ms |
48300 KB |
Output is partially correct |
33 |
Partially correct |
131 ms |
48208 KB |
Output is partially correct |
34 |
Partially correct |
146 ms |
48488 KB |
Output is partially correct |
35 |
Partially correct |
130 ms |
48200 KB |
Output is partially correct |
36 |
Partially correct |
138 ms |
48280 KB |
Output is partially correct |
37 |
Partially correct |
138 ms |
48172 KB |
Output is partially correct |
38 |
Partially correct |
139 ms |
48284 KB |
Output is partially correct |
39 |
Partially correct |
139 ms |
48208 KB |
Output is partially correct |
40 |
Partially correct |
151 ms |
48268 KB |
Output is partially correct |
41 |
Partially correct |
182 ms |
48280 KB |
Output is partially correct |
42 |
Partially correct |
139 ms |
48208 KB |
Output is partially correct |
43 |
Partially correct |
139 ms |
48252 KB |
Output is partially correct |
44 |
Partially correct |
139 ms |
48188 KB |
Output is partially correct |
45 |
Partially correct |
151 ms |
48208 KB |
Output is partially correct |
46 |
Partially correct |
158 ms |
48220 KB |
Output is partially correct |
47 |
Partially correct |
155 ms |
48228 KB |
Output is partially correct |
48 |
Partially correct |
135 ms |
48224 KB |
Output is partially correct |
49 |
Partially correct |
175 ms |
48280 KB |
Output is partially correct |
50 |
Partially correct |
143 ms |
48212 KB |
Output is partially correct |
51 |
Partially correct |
147 ms |
48280 KB |
Output is partially correct |
52 |
Partially correct |
149 ms |
48272 KB |
Output is partially correct |
53 |
Partially correct |
147 ms |
48284 KB |
Output is partially correct |
54 |
Partially correct |
145 ms |
48208 KB |
Output is partially correct |
55 |
Partially correct |
141 ms |
48272 KB |
Output is partially correct |
56 |
Partially correct |
139 ms |
48180 KB |
Output is partially correct |
57 |
Partially correct |
166 ms |
48280 KB |
Output is partially correct |
58 |
Partially correct |
132 ms |
48284 KB |
Output is partially correct |
59 |
Partially correct |
140 ms |
48208 KB |
Output is partially correct |
60 |
Partially correct |
142 ms |
48272 KB |
Output is partially correct |
61 |
Partially correct |
176 ms |
48208 KB |
Output is partially correct |
62 |
Correct |
19 ms |
48052 KB |
Output is correct |
63 |
Correct |
23 ms |
47952 KB |
Output is correct |
64 |
Correct |
30 ms |
48040 KB |
Output is correct |
65 |
Correct |
20 ms |
48056 KB |
Output is correct |
66 |
Correct |
20 ms |
48008 KB |
Output is correct |
67 |
Correct |
20 ms |
48004 KB |
Output is correct |
68 |
Correct |
20 ms |
47952 KB |
Output is correct |
69 |
Correct |
20 ms |
47952 KB |
Output is correct |
70 |
Correct |
22 ms |
48028 KB |
Output is correct |
71 |
Correct |
22 ms |
47972 KB |
Output is correct |
72 |
Correct |
27 ms |
47952 KB |
Output is correct |
73 |
Correct |
24 ms |
48032 KB |
Output is correct |
74 |
Correct |
20 ms |
48004 KB |
Output is correct |
75 |
Correct |
22 ms |
47928 KB |
Output is correct |
76 |
Correct |
19 ms |
47952 KB |
Output is correct |
77 |
Correct |
19 ms |
47952 KB |
Output is correct |
78 |
Correct |
20 ms |
47948 KB |
Output is correct |
79 |
Correct |
22 ms |
48020 KB |
Output is correct |
80 |
Correct |
20 ms |
48020 KB |
Output is correct |
81 |
Correct |
19 ms |
47952 KB |
Output is correct |
82 |
Correct |
19 ms |
48028 KB |
Output is correct |
83 |
Correct |
19 ms |
48060 KB |
Output is correct |
84 |
Correct |
25 ms |
47956 KB |
Output is correct |
85 |
Correct |
19 ms |
47952 KB |
Output is correct |
86 |
Correct |
19 ms |
48056 KB |
Output is correct |
87 |
Correct |
18 ms |
47992 KB |
Output is correct |
88 |
Correct |
19 ms |
48032 KB |
Output is correct |
89 |
Correct |
21 ms |
48020 KB |
Output is correct |
90 |
Correct |
20 ms |
47980 KB |
Output is correct |
91 |
Correct |
20 ms |
47952 KB |
Output is correct |