#include <bits/stdc++.h>
using namespace std;
#include "mushrooms.h"
#define loop(x, i) for (int i = 0; i < x; i++)
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef set<int> si;
typedef vector<vi> vvi;
int count_mushrooms(int n)
{
int Q = 0;
vi A = {0}, B;
int c1 = use_machine({0, 1});
Q++;
int i = 2;
if (c1 == 1)
{
if (n == 2)
return 1;
B.pb(1);
int c2 = use_machine({1, 2});
Q++;
i++;
if (c2 == 1)
A.pb(2);
else
B.pb(2);
}
else
{
A.pb(1);
}
int x = 241;
while (max(A.size(), B.size()) < x)
{
if (A.size() >= 2)
{
if (i + 1 >= n)
break;
int res = use_machine({A[0], i, A[1], i + 1});
Q++;
if (Q>800) throw;
if (res == 0)
{
A.pb(i);
A.pb(i + 1);
}
else if (res == 1)
{
A.pb(i);
}
else if (res == 2)
{
A.pb(i + 1);
}
i += 2;
}
else
{
if (i + 1 >= n)
break;
int res = use_machine({B[0], i, B[1], i + 1});
Q++;
if (Q>800) throw;
if (res == 3)
{
A.pb(i);
A.pb(i + 1);
}
else if (res == 2)
{
A.pb(i);
}
else if (res == 1)
{
A.pb(i + 1);
}
i += 2;
}
}
if (i == n - 1)
{
if (use_machine({0, i}) == 0)
A.pb(i);
i++;
Q++;
}
int res = A.size();
for (; i < n; i += x)
{
vi q;
if (A.size() >= x)
{
int l = min(x, n - i);
loop(l, j)
{
q.pb(A.at(j));
q.pb(i + j);
}
int c3 = use_machine(q);
if (c3 % 2 == 1) c3++;
res += l - (c3 / 2);
q.clear();
}
else
{
int l = min(x, n - i);
loop(l, j)
{
q.pb(B.at(j));
q.pb(i + j);
}
int c3 = use_machine(q);
if (c3 % 2 == 1) c3++;
res += (c3 / 2);
q.clear();
}
}
return res;
}
Compilation message
mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:38:33: warning: comparison of integer expressions of different signedness: 'const long unsigned int' and 'int' [-Wsign-compare]
38 | while (max(A.size(), B.size()) < x)
| ~~~~~~~~~~~~~~~~~~~~~~~~^~~
mushrooms.cpp:96:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
96 | if (A.size() >= x)
| ~~~~~~~~~^~~~
# |
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 |
2 ms |
344 KB |
Output is correct |
7 |
Correct |
3 ms |
344 KB |
Output is correct |
8 |
Correct |
3 ms |
344 KB |
Output is correct |
9 |
Correct |
3 ms |
344 KB |
Output is correct |
10 |
Partially correct |
3 ms |
344 KB |
Output is partially correct |
11 |
Partially correct |
6 ms |
440 KB |
Output is partially correct |
12 |
Partially correct |
4 ms |
344 KB |
Output is partially correct |
13 |
Runtime error |
4 ms |
344 KB |
Execution killed with signal 6 |
14 |
Halted |
0 ms |
0 KB |
- |