#include "mushrooms.h"
#include <bits/stdc++.h>
using namespace std;
const int k=10;
vector <int> a,b;
int t,res,sz;
int count_mushrooms(int n){
if (0){
for (int i=1;i<n;i++)
res+=1-use_machine({0,i});
return res+1;
}
a.push_back(0);
for (int i=1;i<=k*2;i++){
if (max(a.size(),b.size())==k)
break;
int x=use_machine({0,i});
if (x)
b.push_back(i);
else
a.push_back(i);
}
sz=a.size();
t=(a.size()!=k);
if (a.size()!=k)
swap(a,b);
for (int i=a.size()+b.size();i<n;i+=k*2){
if (i==n-1){
res+=abs(t-use_machine({0,i}));
continue;
}
vector <int> ve;
if (n-i<k){
for (int j=i;j<n;j++){
ve.push_back(a[j-i]);
ve.push_back(j);
}
ve.push_back(a[n-i]);
res+=use_machine(ve)/2;
break;
}
for (int j=i;j<min(i+k+1,n);j++){
ve.push_back(j);
if (j-i<k)
ve.push_back(a[j-i]);
}
if (n-i-1<k)
ve.pop_back();
int x=use_machine(ve);
if (i==n-2){
res+=x;
continue;
}
int l=ve[0],r=ve.back();
ve.clear();
ve.push_back(l);
for (int j=min(i+k+1,n);j<min(i+k*2,n);j++){
ve.push_back(a[j-i-k-1]);
ve.push_back(j);
}
ve.push_back(a[min(i+k*2,n)-min(i+k+1,n)]);
ve.push_back(r);
res+=(x+use_machine(ve))/2;
}
return (t?res:n-a.size()-b.size()-res)+sz;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Invalid value 3 in the query array. |
2 |
Halted |
0 ms |
0 KB |
- |