#include "insects.h"
#include <bits/stdc++.h>
using namespace std;
int A (int n, vector < int > V){
vector < bool > fix (n, 1);
for (int x : V)
fix[x] = 0;
int m = (int)V.size();
vector < int > L(n, 0);
vector < int > R(n, m-1);
vector < int > M(n);
for (int I = 0; (1 << I) < m*2; I++){
vector < int > v[m];
bool ok = 1;
for (int i = 0; i < n; i++){
if (fix[i] == 0)
continue;
if (L[i] == R[i])
continue;
ok = 0;
M[i] = (L[i] + R[i] >> 1);
v[M[i]].push_back (i);
}
if (ok)
break;
for (int i = 0; i < m; i++){
move_inside(V[i]);
for (int x : v[i]){
move_inside(x);
if (press_button() == 1)
L[x] = M[x] + 1;
else
R[x] = M[x];
move_outside(x);
}
}
for (int x : V)
move_outside(x);
}
vector < int > cnt (m, 1);
for (int i = 0; i < n; i++)
if (fix[i])
cnt[L[i]]++;
int ans = cnt[0];
for (int i = 1; i < m; i++)
ans = min (ans, cnt[i]);
return ans;
}
int B (int n, vector < int > V){
vector < bool > fix (n, 1);
for (int x : V)
fix[x] = 0;
int ans = 1;
int m = (int)V.size();
while (1){
V.clear();
for (int i = 0; i < n; i++)
if (fix[i])
V.push_back(i);
if ((int)V.size() < m)
return ans;
vector < int > v;
for (int x : V){
move_inside(x);
if (press_button() == 1){
v.push_back(x);
fix[x] = 0;
}
else
move_outside(x);
}
for (int x : v)
move_outside(x);
if ((int)v.size() < m)
return ans;
ans++;
}
return ans;
}
int C (int n, int m, vector < int > V){
int l = 1, r = n/m;
//cout << l << " " << r << endl;
while (l < r){
int mid = l + r + 1 >> 1;
vector < int > v;
for (int i : V){
move_inside(i);
if (press_button() < mid){
v.push_back(i);
}
else
move_outside(i);
}
for (int x : v)
move_outside(x);
if ((int)v.size() == m*(mid-1))
l = mid;
else
r = mid - 1;
}
return l;
}
int min_cardinality(int n) {
vector < int > V;
for (int i = 0; i < n; i++){
move_inside(i);
if (press_button() == 1)
V.push_back(i);
else
move_outside(i);
}
for (int x : V)
move_outside(x);
int m = (int)V.size();
int k = n - m;
int ans1 = 0;
while ((1 << ans1) < m)
ans1++;
ans1 *= n;
int ans2 = 0;
while (k >= m){
ans2 += k;
k -= m;
}
//cout << ans1 << " " << ans2 << endl;
if (m*m < n)
return A(n, V);
vector < bool > fix (n, 1);
for (int x : V)
fix[x] = 0;
V.clear();
for (int i = 0; i < n; i++)
if (fix[i])
V.push_back (i);
return C(n, m, V);
}
Compilation message
insects.cpp: In function 'int A(int, std::vector<int>)':
insects.cpp:22:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
22 | M[i] = (L[i] + R[i] >> 1);
insects.cpp: In function 'int C(int, int, std::vector<int>)':
insects.cpp:87:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
87 | int mid = l + r + 1 >> 1;
| ~~~~~~^~~
# |
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 |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
2 ms |
208 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
9 ms |
208 KB |
Output is correct |
9 |
Correct |
8 ms |
208 KB |
Output is correct |
10 |
Correct |
7 ms |
336 KB |
Output is correct |
11 |
Correct |
2 ms |
208 KB |
Output is correct |
12 |
Correct |
8 ms |
208 KB |
Output is correct |
13 |
Correct |
13 ms |
304 KB |
Output is correct |
14 |
Correct |
6 ms |
208 KB |
Output is correct |
15 |
Correct |
8 ms |
300 KB |
Output is correct |
16 |
Correct |
7 ms |
208 KB |
Output is correct |
17 |
Correct |
7 ms |
300 KB |
Output is correct |
18 |
Correct |
8 ms |
300 KB |
Output is correct |
19 |
Correct |
7 ms |
208 KB |
Output is correct |
20 |
Correct |
5 ms |
208 KB |
Output is correct |
21 |
Correct |
4 ms |
208 KB |
Output is correct |
22 |
Correct |
2 ms |
208 KB |
Output is correct |
# |
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 |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
2 ms |
208 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
9 ms |
208 KB |
Output is correct |
9 |
Correct |
8 ms |
208 KB |
Output is correct |
10 |
Correct |
7 ms |
336 KB |
Output is correct |
11 |
Correct |
2 ms |
208 KB |
Output is correct |
12 |
Correct |
8 ms |
208 KB |
Output is correct |
13 |
Correct |
13 ms |
304 KB |
Output is correct |
14 |
Correct |
6 ms |
208 KB |
Output is correct |
15 |
Correct |
8 ms |
300 KB |
Output is correct |
16 |
Correct |
7 ms |
208 KB |
Output is correct |
17 |
Correct |
7 ms |
300 KB |
Output is correct |
18 |
Correct |
8 ms |
300 KB |
Output is correct |
19 |
Correct |
7 ms |
208 KB |
Output is correct |
20 |
Correct |
5 ms |
208 KB |
Output is correct |
21 |
Correct |
4 ms |
208 KB |
Output is correct |
22 |
Correct |
2 ms |
208 KB |
Output is correct |
23 |
Correct |
8 ms |
208 KB |
Output is correct |
24 |
Correct |
9 ms |
300 KB |
Output is correct |
25 |
Correct |
50 ms |
300 KB |
Output is correct |
26 |
Correct |
43 ms |
304 KB |
Output is correct |
27 |
Correct |
22 ms |
292 KB |
Output is correct |
28 |
Correct |
8 ms |
304 KB |
Output is correct |
29 |
Correct |
28 ms |
292 KB |
Output is correct |
30 |
Correct |
57 ms |
328 KB |
Output is correct |
31 |
Correct |
28 ms |
300 KB |
Output is correct |
32 |
Correct |
24 ms |
280 KB |
Output is correct |
33 |
Correct |
40 ms |
208 KB |
Output is correct |
34 |
Correct |
32 ms |
300 KB |
Output is correct |
35 |
Correct |
55 ms |
428 KB |
Output is correct |
36 |
Correct |
43 ms |
304 KB |
Output is correct |
37 |
Correct |
36 ms |
300 KB |
Output is correct |
38 |
Correct |
43 ms |
276 KB |
Output is correct |
39 |
Correct |
29 ms |
300 KB |
Output is correct |
40 |
Correct |
18 ms |
328 KB |
Output is correct |
41 |
Correct |
9 ms |
208 KB |
Output is correct |
# |
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 |
1 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 |
24 ms |
276 KB |
Output is correct |
8 |
Correct |
20 ms |
308 KB |
Output is correct |
9 |
Partially correct |
75 ms |
420 KB |
Output is partially correct |
10 |
Partially correct |
116 ms |
320 KB |
Output is partially correct |
11 |
Correct |
46 ms |
208 KB |
Output is correct |
12 |
Correct |
29 ms |
300 KB |
Output is correct |
13 |
Partially correct |
55 ms |
280 KB |
Output is partially correct |
14 |
Partially correct |
104 ms |
424 KB |
Output is partially correct |
15 |
Partially correct |
70 ms |
328 KB |
Output is partially correct |
16 |
Partially correct |
81 ms |
288 KB |
Output is partially correct |
17 |
Partially correct |
77 ms |
408 KB |
Output is partially correct |
18 |
Partially correct |
84 ms |
320 KB |
Output is partially correct |
19 |
Partially correct |
40 ms |
288 KB |
Output is partially correct |
20 |
Partially correct |
82 ms |
324 KB |
Output is partially correct |
21 |
Partially correct |
73 ms |
304 KB |
Output is partially correct |
22 |
Partially correct |
108 ms |
288 KB |
Output is partially correct |
23 |
Partially correct |
39 ms |
300 KB |
Output is partially correct |
24 |
Correct |
46 ms |
296 KB |
Output is correct |
25 |
Correct |
26 ms |
308 KB |
Output is correct |
26 |
Correct |
21 ms |
300 KB |
Output is correct |
27 |
Partially correct |
111 ms |
312 KB |
Output is partially correct |
28 |
Partially correct |
141 ms |
416 KB |
Output is partially correct |
29 |
Partially correct |
123 ms |
320 KB |
Output is partially correct |
30 |
Partially correct |
91 ms |
328 KB |
Output is partially correct |
31 |
Partially correct |
107 ms |
436 KB |
Output is partially correct |
32 |
Partially correct |
99 ms |
396 KB |
Output is partially correct |
33 |
Partially correct |
83 ms |
276 KB |
Output is partially correct |
34 |
Partially correct |
39 ms |
304 KB |
Output is partially correct |
35 |
Partially correct |
102 ms |
336 KB |
Output is partially correct |
36 |
Partially correct |
128 ms |
436 KB |
Output is partially correct |
37 |
Partially correct |
139 ms |
304 KB |
Output is partially correct |
38 |
Partially correct |
89 ms |
408 KB |
Output is partially correct |
39 |
Partially correct |
86 ms |
292 KB |
Output is partially correct |
40 |
Partially correct |
91 ms |
312 KB |
Output is partially correct |
41 |
Partially correct |
93 ms |
440 KB |
Output is partially correct |
42 |
Partially correct |
143 ms |
304 KB |
Output is partially correct |
43 |
Partially correct |
17 ms |
276 KB |
Output is partially correct |
44 |
Partially correct |
70 ms |
288 KB |
Output is partially correct |
45 |
Correct |
40 ms |
284 KB |
Output is correct |
46 |
Correct |
27 ms |
276 KB |
Output is correct |
47 |
Correct |
34 ms |
304 KB |
Output is correct |
48 |
Correct |
25 ms |
284 KB |
Output is correct |