#include "mushrooms.h"
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define pb push_back
#define fi first
#define se second
#define dd(x) cout<<#x<<" is "<<x<<endl;
#define dd2(x,y) cout<<#x<<" is "<<x<<" "<<#y<<" is "<<y<<endl;
#define dl(x) cout<<#x<<" is "<<endl; for(auto i:x) cout<<i<<" "; cout<<endl;
vector<int>a;
vector<int>b;
int res;
void get2(int &x, int &y, int &type){
if(use_machine({0,1})){
b.pb(1);
if(use_machine({0,2})){
b.pb(2);
x=1,y=2,type=1;
} else {
a.pb(2);
x=0,y=2,type=0;
}
} else {
a.pb(1);
x=0, y=1, type=0;
}
}
void get100(int x, int y, vector<int> &v, vector<int> &w, int n){
for(int i=3; i<n-1; i+=2){
int res = use_machine({x,i,y,i+1});
if(res == 0) v.pb(i), v.pb(i+1);
else if(res == 1) v.pb(i), w.pb(i+1);
else if(res == 2) v.pb(i+1), w.pb(i);
else w.pb(i), w.pb(i+1);
if(v.size() >= 142 or w.size() >= 142) break;
}
}
void query(vector<int> &v, vector<int>&x, int n){
vector<int>m;
for(int i=0; i<n; i++) {
m.pb(v[i]);
m.pb(x[i]);
}
res += n-(use_machine(m)+1)/2;
}
int count_mushrooms(int n) {
if(n<205){
int ans = 1;
for(int i=1; i<n; i++){
if(!use_machine({0,i})) ans++;
}
return ans;
}
a.pb(0);
int x,y,type;
get2(x,y,type);
if(type == 0) get100(x,y,a,b,n);
else get100(x,y,b,a,n);
bool f=0;
if(b.size() >= 142) swap(a,b), f=1;
int st=a.size() + b.size();
vector<int>test;
for(int i=st; i<n; i++){
test.pb(i);
if(test.size()==142){
query(a,test,142);
test.clear();
}
}
query(a,test,test.size());
res += a.size();
if(f) res=n-res;
return res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |