#include <bits/stdc++.h>
#include "mushrooms.h"
using namespace std;
int count_mushrooms(int n){
vector<int> w,b;
char c;
int s,ans=0;
vector<int> arr={0,1};
w.push_back(0);
if(use_machine(arr)){
b.push_back(1);
arr={0,2};
if(use_machine(arr)){
b.push_back(2);
c='b';
} else {
w.push_back(2);
c='w';
}
s=3;
} else {
w.push_back(1);
c='w';
s=2;
}
int d=min(100,(n-s)/2);
while(d--){
if(c=='w'){
arr={w[0],s,w[1],s+1};
int tmp=use_machine(arr);
if(tmp%2){
b.push_back(s+1);
} else {
w.push_back(s+1);
}
if(tmp/2){
b.push_back(s);
} else {
w.push_back(s);
}
s+=2;
} else {
arr={b[0],s,b[1],s+1};
int tmp=use_machine(arr);
if(tmp%2){
w.push_back(s+1);
} else {
b.push_back(s+1);
}
if(tmp/2){
w.push_back(s);
} else {
b.push_back(s);
}
s+=2;
}
}
ans=w.size();
int sz=max(b.size(),w.size());
while(n-s>=sz){
arr.resize(sz*2);
if(w.size()>b.size()){
for(int i=0;i<sz;i++,s++){
arr[i*2]=w[i];
arr[i*2+1]=s;
}
int t=use_machine(arr);
if(t%2)b.push_back(s-1);
else w.push_back(s-1);
ans+=sz-(t+1)/2;
} else {
for(int i=0;i<sz;i++,s++){
arr[i*2]=b[i];
arr[i*2+1]=s;
}
int t=use_machine(arr);
if(t%2)w.push_back(s-1);
else b.push_back(s-1);
ans+=(t+1)/2;
}
sz=max(b.size(),w.size());
}
arr.resize((n-s)*2);
if(w.size()>b.size()){
for(int i=0;s<n;i++,s++){
arr[i*2]=w[i];
arr[i*2+1]=s;
}
int t=use_machine(arr);
if(t%2)b.push_back(s-1);
else w.push_back(s-1);
ans+=sz-(t+1)/2;
} else {
for(int i=0;s<n;i++,s++){
arr[i*2]=b[i];
arr[i*2+1]=s;
}
int t=use_machine(arr);
if(t%2)w.push_back(s-1);
else b.push_back(s-1);
ans+=(t+1)/2;
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Too small array for query. |
2 |
Halted |
0 ms |
0 KB |
- |