#include "mushrooms.h"
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
typedef long long ll;
typedef std::pair<ll,ll> pll;
using namespace std;
vector<int> A, B, U;
int CNT = 0;
int use_my_machine(vector<int> vec) {
int res = use_machine(vec);
++CNT;
return res;
}
#define use_machine use_my_machine
void query1()
{
if (!U.size())
return;
int x = U.back();
U.pop_back();
(use_machine({0, x})? B: A).push_back(x);
}
void query2()
{
if (U.size() < 2 || (A.size() < 2 && B.size() < 2))
return query1();
int x = U.back(); U.pop_back();
int y = U.back(); U.pop_back();
if (A.size() >= 2) {
int res = use_machine({A[0], x, A[1], y});
int a = res/2;
int b = res%2;
(a? B: A).push_back(x);
(b? B: A).push_back(y);
} else {
int res = use_machine({B[0], x, B[1], y});
int a = res/2;
int b = res%2;
(a? A: B).push_back(x);
(b? A: B).push_back(y);
}
}
void queryx(vector<int> &A, vector<int> &B)
{
int u[5];
Loop (i,0,3) {
u[i] = U.back();
U.pop_back();
}
int res = use_machine({u[0], A[0], u[1], A[1], u[2], A[2]});
int r0 = res&1; res -= r0;
(r0? B: A).push_back(u[0]);
if (res == 0) {
A.push_back(u[1]);
A.push_back(u[2]);
return;
}
if (res == 4) {
B.push_back(u[1]);
B.push_back(u[2]);
return;
}
Loop (i,3,5) {
u[i] = U.back();
U.pop_back();
}
res = use_machine({u[3], A[0], u[4], A[1], u[1], A[2], B[0], u[2], B[1]});
res -= 1;
int r3 = res/1%2;
int r4 = res/2%2;
int r12 = res/4%2;
(r3? B: A).push_back(u[3]);
(r4? B: A).push_back(u[4]);
(r12? B: A).push_back(u[1]);
(r12? A: B).push_back(u[2]);
}
int try_now()
{
int cnt = A.size() + B.size();
int rem = U.size();
int ans = 0;
while (rem > 0) {
int x = max<int>(max(A.size(), B.size()), (cnt+1)/2);
x = min(x, rem);
rem -= x;
++cnt;
++ans;
}
return ans;
}
int other_A = 0;
void queryline()
{
if (!U.size())
return;
auto &C = A.size() > B.size()? A: B;
int cnt = min(C.size(), U.size());
vector<int> vec;
int lst = -1;
Loop (i,0,cnt) {
vec.push_back(C[i]);
vec.push_back(U.back());
lst = U.back();
U.pop_back();
}
int res = use_machine(vec);
int rl = res&1;
if (A.size() > B.size()) {
other_A += cnt-1-res/2;
(rl? B: A).push_back(lst);
} else {
other_A += res/2;
(rl? A: B).push_back(lst);
}
}
int count_mushrooms(int n) {
A.clear(); U.clear(); B.clear(); other_A = 0;
CNT = 0;
A.push_back(0);
Loop (i,1,n)
U.push_back(i);
while (CNT + try_now() > 227) {
if (A.size() >= 3 && B.size() >= 2 && U.size() >= 5)
queryx(A, B);
else if (A.size() >= 2 && B.size() >= 3 && U.size() >= 5)
queryx(B, A);
else
query2();
}
//cerr << CNT << ' ' << try_now() << '\n';
while (U.size())
queryline();
//cerr << CNT << '\n';
return A.size() + other_A;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
5 ms |
464 KB |
Output is correct |
8 |
Correct |
5 ms |
464 KB |
Output is correct |
9 |
Correct |
4 ms |
464 KB |
Output is correct |
10 |
Correct |
6 ms |
464 KB |
Output is correct |
11 |
Correct |
5 ms |
464 KB |
Output is correct |
12 |
Correct |
5 ms |
464 KB |
Output is correct |
13 |
Correct |
5 ms |
464 KB |
Output is correct |
14 |
Correct |
4 ms |
336 KB |
Output is correct |
15 |
Correct |
5 ms |
464 KB |
Output is correct |
16 |
Correct |
7 ms |
464 KB |
Output is correct |
17 |
Correct |
4 ms |
336 KB |
Output is correct |
18 |
Correct |
4 ms |
464 KB |
Output is correct |
19 |
Correct |
5 ms |
464 KB |
Output is correct |
20 |
Correct |
5 ms |
464 KB |
Output is correct |
21 |
Correct |
6 ms |
416 KB |
Output is correct |
22 |
Correct |
5 ms |
464 KB |
Output is correct |
23 |
Correct |
5 ms |
464 KB |
Output is correct |
24 |
Correct |
4 ms |
404 KB |
Output is correct |
25 |
Correct |
7 ms |
464 KB |
Output is correct |
26 |
Correct |
6 ms |
512 KB |
Output is correct |
27 |
Correct |
6 ms |
464 KB |
Output is correct |
28 |
Correct |
6 ms |
464 KB |
Output is correct |
29 |
Correct |
5 ms |
464 KB |
Output is correct |
30 |
Correct |
5 ms |
464 KB |
Output is correct |
31 |
Correct |
5 ms |
464 KB |
Output is correct |
32 |
Correct |
5 ms |
464 KB |
Output is correct |
33 |
Correct |
5 ms |
464 KB |
Output is correct |
34 |
Correct |
5 ms |
464 KB |
Output is correct |
35 |
Correct |
5 ms |
464 KB |
Output is correct |
36 |
Correct |
7 ms |
464 KB |
Output is correct |
37 |
Correct |
5 ms |
464 KB |
Output is correct |
38 |
Correct |
5 ms |
464 KB |
Output is correct |
39 |
Correct |
5 ms |
464 KB |
Output is correct |
40 |
Correct |
5 ms |
464 KB |
Output is correct |
41 |
Correct |
6 ms |
464 KB |
Output is correct |
42 |
Correct |
6 ms |
464 KB |
Output is correct |
43 |
Correct |
4 ms |
464 KB |
Output is correct |
44 |
Correct |
5 ms |
464 KB |
Output is correct |
45 |
Correct |
6 ms |
464 KB |
Output is correct |
46 |
Correct |
5 ms |
464 KB |
Output is correct |
47 |
Correct |
5 ms |
464 KB |
Output is correct |
48 |
Correct |
4 ms |
464 KB |
Output is correct |
49 |
Correct |
5 ms |
464 KB |
Output is correct |
50 |
Correct |
6 ms |
464 KB |
Output is correct |
51 |
Correct |
6 ms |
464 KB |
Output is correct |
52 |
Correct |
5 ms |
464 KB |
Output is correct |
53 |
Correct |
5 ms |
464 KB |
Output is correct |
54 |
Correct |
5 ms |
464 KB |
Output is correct |
55 |
Partially correct |
4 ms |
464 KB |
Output is partially correct |
56 |
Partially correct |
5 ms |
464 KB |
Output is partially correct |
57 |
Correct |
5 ms |
464 KB |
Output is correct |
58 |
Correct |
5 ms |
464 KB |
Output is correct |
59 |
Correct |
6 ms |
464 KB |
Output is correct |
60 |
Correct |
5 ms |
464 KB |
Output is correct |
61 |
Correct |
5 ms |
464 KB |
Output is correct |
62 |
Correct |
0 ms |
208 KB |
Output is correct |
63 |
Correct |
0 ms |
208 KB |
Output is correct |
64 |
Correct |
1 ms |
208 KB |
Output is correct |
65 |
Correct |
0 ms |
208 KB |
Output is correct |
66 |
Correct |
0 ms |
208 KB |
Output is correct |
67 |
Correct |
0 ms |
208 KB |
Output is correct |
68 |
Correct |
0 ms |
208 KB |
Output is correct |
69 |
Correct |
0 ms |
208 KB |
Output is correct |
70 |
Correct |
0 ms |
208 KB |
Output is correct |
71 |
Correct |
0 ms |
208 KB |
Output is correct |
72 |
Correct |
1 ms |
208 KB |
Output is correct |
73 |
Correct |
0 ms |
208 KB |
Output is correct |
74 |
Correct |
0 ms |
208 KB |
Output is correct |
75 |
Correct |
0 ms |
208 KB |
Output is correct |
76 |
Correct |
0 ms |
208 KB |
Output is correct |
77 |
Correct |
0 ms |
208 KB |
Output is correct |
78 |
Correct |
0 ms |
208 KB |
Output is correct |
79 |
Correct |
0 ms |
208 KB |
Output is correct |
80 |
Correct |
0 ms |
208 KB |
Output is correct |
81 |
Correct |
0 ms |
208 KB |
Output is correct |
82 |
Correct |
0 ms |
208 KB |
Output is correct |
83 |
Correct |
0 ms |
208 KB |
Output is correct |
84 |
Correct |
0 ms |
208 KB |
Output is correct |
85 |
Correct |
0 ms |
208 KB |
Output is correct |
86 |
Correct |
0 ms |
208 KB |
Output is correct |
87 |
Correct |
0 ms |
208 KB |
Output is correct |
88 |
Correct |
0 ms |
208 KB |
Output is correct |
89 |
Correct |
0 ms |
208 KB |
Output is correct |
90 |
Correct |
0 ms |
208 KB |
Output is correct |
91 |
Correct |
0 ms |
208 KB |
Output is correct |