#include "bits/stdc++.h"
//#define int long long
#define all(v) v.begin() , v.end()
#define sz(a) (int)a.size()
#include "mushrooms.h"
using namespace std;
const int S = 142;
int count_mushrooms(int n) {
vector<int> v[2];
int ansA=0;
v[0].push_back(0);
for(int i=1;i<n;){
if(i==n-1){
if(use_machine({0,i})) v[1].push_back(i);
else v[0].push_back(i);
i++;
break;
}
if(sz(v[0])<2 && sz(v[1])<2){
if(use_machine({0,i})) v[1].push_back(i);
else v[0].push_back(i);
i++;
}
else if(sz(v[0])<S && sz(v[1])<S){
if(sz(v[0])>=2){
int res = use_machine({v[0][0],i,v[0][1],i+1});
if(res&1) v[1].push_back(i+1);
else v[0].push_back(i+1);
if(res&2) v[1].push_back(i);
else v[0].push_back(i);
i+=2;
}
else{
int res = use_machine({v[1][0],i,v[1][1],i+1});
if(res&1) v[0].push_back(i+1);
else v[1].push_back(i+1);
if(res&2) v[0].push_back(i);
else v[1].push_back(i);
i+=2;
}
}
else{
if(sz(v[0])>=S){
vector<int> cur;
cur.push_back(v[0][0]);
int p=0;
while(i<n-1 && p<S){
cur.push_back(i++);
cur.push_back(v[0][++p]);
}
cur.push_back(i++);
int res=use_machine(cur);
if(!(res&1)) ansA++;
ansA+=sz(cur)/2-1-res/2;
}
else{
vector<int> cur;
cur.push_back(v[1][0]);
int p=0;
while(i<n-1 && p<S){
cur.push_back(i++);
cur.push_back(v[1][++p]);
}
cur.push_back(i++);
int res=use_machine(cur);
if(res&1) ansA++;
ansA+=res/2;
}
}
}
return sz(v[0]) + ansA;
}
# |
Verdict |
Execution time |
Memory |
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 |
Incorrect |
0 ms |
344 KB |
Duplicate value 0 in the query array. |
8 |
Halted |
0 ms |
0 KB |
- |