#include "insects.h"
#include <bits/stdc++.h>
using namespace std;
int uniq_cnt;
vector<int> cands;
vector<int> st;
int cnt = 0;
void insert(int n, int p) {
for (int x: cands) {
if (cnt < p && find(st.begin(), st.end(), x) != st.end()) continue;
move_inside(x);
st.push_back(x);
if (press_button() > p) {
move_outside(x);
st.pop_back();
}
}
cnt = p;
}
void clear() {
while (!st.empty()) {
move_outside(st.back());
st.pop_back();
}
}
int min_cardinality(int n) {
for (int i=0; i<n; ++i) cands.push_back(i);
insert(n, 1);
uniq_cnt = st.size();
int low = 1, high = n / uniq_cnt;
int offset = 0;
while (low < high) {
int mid = (low + high + 1) / 2;
if (cnt >= mid) clear();
insert(n, mid);
if (st.size() == uniq_cnt * mid) {
offset += mid;
low = 0;
high = high - mid;
vector<int> tmp;
for (int x: cands) {
if (find(st.begin(), st.end(), x) == st.end()) tmp.push_back(x);
}
cands = tmp;
} else {
high = mid-1;
cands = st;
}
}
return low + offset;
}
Compilation message
insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:42:23: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
42 | if (st.size() == uniq_cnt * mid) {
| ~~~~~~~~~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
8 ms |
208 KB |
Output is correct |
7 |
Correct |
3 ms |
208 KB |
Output is correct |
8 |
Correct |
6 ms |
208 KB |
Output is correct |
9 |
Correct |
5 ms |
208 KB |
Output is correct |
10 |
Correct |
4 ms |
208 KB |
Output is correct |
11 |
Correct |
2 ms |
208 KB |
Output is correct |
12 |
Correct |
7 ms |
208 KB |
Output is correct |
13 |
Correct |
5 ms |
208 KB |
Output is correct |
14 |
Correct |
5 ms |
208 KB |
Output is correct |
15 |
Correct |
5 ms |
208 KB |
Output is correct |
16 |
Correct |
5 ms |
208 KB |
Output is correct |
17 |
Correct |
6 ms |
208 KB |
Output is correct |
18 |
Correct |
5 ms |
208 KB |
Output is correct |
19 |
Correct |
4 ms |
208 KB |
Output is correct |
20 |
Correct |
4 ms |
208 KB |
Output is correct |
21 |
Correct |
4 ms |
208 KB |
Output is correct |
22 |
Correct |
3 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
8 ms |
208 KB |
Output is correct |
7 |
Correct |
3 ms |
208 KB |
Output is correct |
8 |
Correct |
6 ms |
208 KB |
Output is correct |
9 |
Correct |
5 ms |
208 KB |
Output is correct |
10 |
Correct |
4 ms |
208 KB |
Output is correct |
11 |
Correct |
2 ms |
208 KB |
Output is correct |
12 |
Correct |
7 ms |
208 KB |
Output is correct |
13 |
Correct |
5 ms |
208 KB |
Output is correct |
14 |
Correct |
5 ms |
208 KB |
Output is correct |
15 |
Correct |
5 ms |
208 KB |
Output is correct |
16 |
Correct |
5 ms |
208 KB |
Output is correct |
17 |
Correct |
6 ms |
208 KB |
Output is correct |
18 |
Correct |
5 ms |
208 KB |
Output is correct |
19 |
Correct |
4 ms |
208 KB |
Output is correct |
20 |
Correct |
4 ms |
208 KB |
Output is correct |
21 |
Correct |
4 ms |
208 KB |
Output is correct |
22 |
Correct |
3 ms |
208 KB |
Output is correct |
23 |
Correct |
31 ms |
284 KB |
Output is correct |
24 |
Correct |
10 ms |
304 KB |
Output is correct |
25 |
Correct |
21 ms |
208 KB |
Output is correct |
26 |
Correct |
29 ms |
416 KB |
Output is correct |
27 |
Correct |
18 ms |
208 KB |
Output is correct |
28 |
Correct |
10 ms |
208 KB |
Output is correct |
29 |
Correct |
23 ms |
208 KB |
Output is correct |
30 |
Correct |
15 ms |
208 KB |
Output is correct |
31 |
Correct |
29 ms |
208 KB |
Output is correct |
32 |
Correct |
24 ms |
208 KB |
Output is correct |
33 |
Correct |
21 ms |
284 KB |
Output is correct |
34 |
Correct |
29 ms |
208 KB |
Output is correct |
35 |
Correct |
30 ms |
208 KB |
Output is correct |
36 |
Correct |
28 ms |
292 KB |
Output is correct |
37 |
Correct |
20 ms |
208 KB |
Output is correct |
38 |
Correct |
27 ms |
208 KB |
Output is correct |
39 |
Correct |
23 ms |
284 KB |
Output is correct |
40 |
Correct |
9 ms |
308 KB |
Output is correct |
41 |
Correct |
9 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
26 ms |
296 KB |
Output is correct |
8 |
Correct |
22 ms |
312 KB |
Output is correct |
9 |
Correct |
53 ms |
300 KB |
Output is correct |
10 |
Correct |
50 ms |
288 KB |
Output is correct |
11 |
Correct |
50 ms |
208 KB |
Output is correct |
12 |
Correct |
25 ms |
208 KB |
Output is correct |
13 |
Correct |
52 ms |
292 KB |
Output is correct |
14 |
Correct |
57 ms |
288 KB |
Output is correct |
15 |
Correct |
52 ms |
208 KB |
Output is correct |
16 |
Correct |
62 ms |
208 KB |
Output is correct |
17 |
Correct |
43 ms |
208 KB |
Output is correct |
18 |
Correct |
54 ms |
208 KB |
Output is correct |
19 |
Partially correct |
54 ms |
208 KB |
Output is partially correct |
20 |
Correct |
50 ms |
424 KB |
Output is correct |
21 |
Correct |
46 ms |
292 KB |
Output is correct |
22 |
Correct |
56 ms |
304 KB |
Output is correct |
23 |
Correct |
52 ms |
288 KB |
Output is correct |
24 |
Correct |
51 ms |
304 KB |
Output is correct |
25 |
Correct |
25 ms |
316 KB |
Output is correct |
26 |
Correct |
15 ms |
292 KB |
Output is correct |
27 |
Correct |
56 ms |
208 KB |
Output is correct |
28 |
Correct |
33 ms |
416 KB |
Output is correct |
29 |
Partially correct |
53 ms |
208 KB |
Output is partially correct |
30 |
Partially correct |
41 ms |
304 KB |
Output is partially correct |
31 |
Correct |
54 ms |
292 KB |
Output is correct |
32 |
Correct |
37 ms |
300 KB |
Output is correct |
33 |
Correct |
46 ms |
208 KB |
Output is correct |
34 |
Correct |
53 ms |
304 KB |
Output is correct |
35 |
Partially correct |
26 ms |
304 KB |
Output is partially correct |
36 |
Partially correct |
51 ms |
296 KB |
Output is partially correct |
37 |
Correct |
42 ms |
304 KB |
Output is correct |
38 |
Correct |
52 ms |
296 KB |
Output is correct |
39 |
Correct |
24 ms |
300 KB |
Output is correct |
40 |
Correct |
42 ms |
292 KB |
Output is correct |
41 |
Partially correct |
50 ms |
428 KB |
Output is partially correct |
42 |
Partially correct |
59 ms |
304 KB |
Output is partially correct |
43 |
Correct |
10 ms |
208 KB |
Output is correct |
44 |
Correct |
33 ms |
208 KB |
Output is correct |
45 |
Correct |
44 ms |
208 KB |
Output is correct |
46 |
Correct |
24 ms |
208 KB |
Output is correct |
47 |
Correct |
29 ms |
208 KB |
Output is correct |
48 |
Correct |
32 ms |
208 KB |
Output is correct |