#include "mushrooms.h"
#include <bits/stdc++.h>
using namespace std;
int res, a, b, m, sz;
vector<int> x, y;
int count_mushrooms(int n) {
if (n<=282)
{
for (int i=1; i<n; i++) if (use_machine(vector<int> {0, i})==0) res++;
return res+1;
}
x.push_back(0);
if (use_machine(vector<int> {0, 1})==0)
{
a=0, b=1, m=0;
x.push_back(1);
if (use_machine(vector<int> {1, 2})==0) x.push_back(2);
else y.push_back(2);
}
else if (use_machine(vector<int> {1, 2})==0) a=1, b=2, m=1, y.push_back(1), y.push_back(2);
else a=0, b=2, m=0, y.push_back(1), x.push_back(2);
for (int i=3; i<282; i+=2)
{
int tmp=use_machine(vector<int> {a, i, b, i+1});
if (m)
{
if (tmp==3) x.push_back(i), x.push_back(i+1);
else if (tmp==2) x.push_back(i), y.push_back(i+1);
else if (tmp==1) x.push_back(i+1), y.push_back(i);
else y.push_back(i), y.push_back(i+1);
}
else
{
if (tmp==3) y.push_back(i), y.push_back(i+1);
else if (tmp==2) y.push_back(i), x.push_back(i+1);
else if (tmp==2) y.push_back(i+1), x.push_back(i);
else x.push_back(i), x.push_back(i+1);
}
}
res=x.size();
if (x.size()>=y.size()) m=0, sz=x.size()-1;
else m=1, sz=y.size()-1;
/*
cout<<"debug x : ";
for (auto z:x) cout<<z<<' ';
cout<<'\n';
cout<<"debug y : ";
for (auto z:y) cout<<z<<' ';
cout<<'\n';
*/
for (int i=283; i<n; i+=sz)
{
vector<int> qrs;
int cnt=0;
for (int j=0; j<sz; j++)
{
if (m) qrs.push_back(y[j]);
else qrs.push_back(x[j]);
if (i+j<n) qrs.push_back(i+j), cnt++;
}
if (m) qrs.push_back(y.back());
else qrs.push_back(x.back());
int tmp=use_machine(qrs)/2;
if (m) res+=tmp;
else res+=cnt-tmp;
}
return res;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
448 KB |
Output is correct |
7 |
Correct |
4 ms |
448 KB |
Output is correct |
8 |
Incorrect |
4 ms |
444 KB |
Answer is not correct. |
9 |
Halted |
0 ms |
0 KB |
- |