#include "insects.h"
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define pii pair<int, int>
#define piii pair<int, pii>
#define pb push_back
#define all(v) v.begin(), v.end()
#define size(v) v.size()
#define f first
#define s second
#define INF 1e9
using namespace std;
int min_cardinality(int N) {
vector<int>inside(N, false);
vector<int>fixed(N, false);
set<int>Machine;
for(int i = 0; i < N; ++i){
move_inside(i);
if(press_button() > 1){
move_outside(i);
}else{
Machine.insert(i);
inside[i] = fixed[i] = true;
}
}
int uni = size(Machine);
vector<int>p(N);
for(int i = 0; i < N; ++i){
p[i] = i;
}
random_shuffle(all(p));
int low = 2, high = N / uni, Res = 1;
while(low <= high){
int mid = (low + high) >> 1;
for(int i : p){
if(uni * mid == size(Machine)) break;
if(!fixed[i]){
move_inside(i);
if(press_button() > mid){
move_outside(i);
}else{
Machine.insert(i);
inside[i] = true;
}
}
}
if(uni * mid == size(Machine)){
low = mid + 1;
Res = mid;
for(int i = 0; i < N; ++i){
if(inside[i]) fixed[i] = true;
}
}else{
high = mid - 1;
for(int i = 0; i < N; ++i){
if(!inside[i]) fixed[i] = true;
else if(!fixed[i]){
move_outside(i);
Machine.erase(i);
inside[i] = false;
}
}
}
}
return Res;
}
Compilation message
insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:41:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::set<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | if(uni * mid == size(Machine)) break;
| ^
insects.cpp:52:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::set<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | if(uni * mid == size(Machine)){
| ^
# |
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 |
3 ms |
296 KB |
Output is correct |
7 |
Correct |
2 ms |
304 KB |
Output is correct |
8 |
Correct |
5 ms |
208 KB |
Output is correct |
9 |
Correct |
5 ms |
300 KB |
Output is correct |
10 |
Correct |
6 ms |
208 KB |
Output is correct |
11 |
Correct |
3 ms |
308 KB |
Output is correct |
12 |
Correct |
7 ms |
296 KB |
Output is correct |
13 |
Correct |
6 ms |
304 KB |
Output is correct |
14 |
Correct |
5 ms |
208 KB |
Output is correct |
15 |
Correct |
8 ms |
308 KB |
Output is correct |
16 |
Correct |
5 ms |
208 KB |
Output is correct |
17 |
Correct |
5 ms |
304 KB |
Output is correct |
18 |
Correct |
6 ms |
208 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 |
3 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 |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
3 ms |
296 KB |
Output is correct |
7 |
Correct |
2 ms |
304 KB |
Output is correct |
8 |
Correct |
5 ms |
208 KB |
Output is correct |
9 |
Correct |
5 ms |
300 KB |
Output is correct |
10 |
Correct |
6 ms |
208 KB |
Output is correct |
11 |
Correct |
3 ms |
308 KB |
Output is correct |
12 |
Correct |
7 ms |
296 KB |
Output is correct |
13 |
Correct |
6 ms |
304 KB |
Output is correct |
14 |
Correct |
5 ms |
208 KB |
Output is correct |
15 |
Correct |
8 ms |
308 KB |
Output is correct |
16 |
Correct |
5 ms |
208 KB |
Output is correct |
17 |
Correct |
5 ms |
304 KB |
Output is correct |
18 |
Correct |
6 ms |
208 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 |
3 ms |
208 KB |
Output is correct |
23 |
Correct |
16 ms |
308 KB |
Output is correct |
24 |
Correct |
8 ms |
336 KB |
Output is correct |
25 |
Correct |
20 ms |
424 KB |
Output is correct |
26 |
Correct |
27 ms |
328 KB |
Output is correct |
27 |
Correct |
23 ms |
304 KB |
Output is correct |
28 |
Correct |
12 ms |
304 KB |
Output is correct |
29 |
Correct |
28 ms |
208 KB |
Output is correct |
30 |
Correct |
29 ms |
284 KB |
Output is correct |
31 |
Correct |
20 ms |
288 KB |
Output is correct |
32 |
Correct |
20 ms |
304 KB |
Output is correct |
33 |
Correct |
19 ms |
320 KB |
Output is correct |
34 |
Correct |
25 ms |
328 KB |
Output is correct |
35 |
Correct |
28 ms |
208 KB |
Output is correct |
36 |
Correct |
18 ms |
288 KB |
Output is correct |
37 |
Correct |
28 ms |
316 KB |
Output is correct |
38 |
Correct |
26 ms |
304 KB |
Output is correct |
39 |
Correct |
18 ms |
312 KB |
Output is correct |
40 |
Correct |
17 ms |
332 KB |
Output is correct |
41 |
Correct |
11 ms |
328 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 |
1 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 |
31 ms |
456 KB |
Output is correct |
8 |
Correct |
16 ms |
384 KB |
Output is correct |
9 |
Correct |
45 ms |
304 KB |
Output is correct |
10 |
Correct |
47 ms |
436 KB |
Output is correct |
11 |
Correct |
53 ms |
324 KB |
Output is correct |
12 |
Correct |
14 ms |
324 KB |
Output is correct |
13 |
Correct |
62 ms |
292 KB |
Output is correct |
14 |
Correct |
45 ms |
296 KB |
Output is correct |
15 |
Correct |
35 ms |
436 KB |
Output is correct |
16 |
Correct |
59 ms |
308 KB |
Output is correct |
17 |
Correct |
31 ms |
328 KB |
Output is correct |
18 |
Correct |
21 ms |
304 KB |
Output is correct |
19 |
Correct |
51 ms |
308 KB |
Output is correct |
20 |
Correct |
44 ms |
320 KB |
Output is correct |
21 |
Correct |
56 ms |
296 KB |
Output is correct |
22 |
Correct |
48 ms |
360 KB |
Output is correct |
23 |
Correct |
51 ms |
320 KB |
Output is correct |
24 |
Correct |
42 ms |
332 KB |
Output is correct |
25 |
Correct |
31 ms |
340 KB |
Output is correct |
26 |
Correct |
21 ms |
340 KB |
Output is correct |
27 |
Correct |
44 ms |
300 KB |
Output is correct |
28 |
Correct |
50 ms |
316 KB |
Output is correct |
29 |
Correct |
38 ms |
316 KB |
Output is correct |
30 |
Correct |
39 ms |
376 KB |
Output is correct |
31 |
Correct |
38 ms |
476 KB |
Output is correct |
32 |
Correct |
54 ms |
348 KB |
Output is correct |
33 |
Correct |
37 ms |
296 KB |
Output is correct |
34 |
Correct |
58 ms |
328 KB |
Output is correct |
35 |
Correct |
65 ms |
368 KB |
Output is correct |
36 |
Correct |
25 ms |
316 KB |
Output is correct |
37 |
Correct |
52 ms |
320 KB |
Output is correct |
38 |
Correct |
52 ms |
300 KB |
Output is correct |
39 |
Correct |
53 ms |
480 KB |
Output is correct |
40 |
Correct |
53 ms |
384 KB |
Output is correct |
41 |
Correct |
44 ms |
428 KB |
Output is correct |
42 |
Correct |
36 ms |
328 KB |
Output is correct |
43 |
Correct |
11 ms |
304 KB |
Output is correct |
44 |
Correct |
47 ms |
292 KB |
Output is correct |
45 |
Correct |
28 ms |
484 KB |
Output is correct |
46 |
Correct |
27 ms |
332 KB |
Output is correct |
47 |
Correct |
30 ms |
360 KB |
Output is correct |
48 |
Correct |
15 ms |
336 KB |
Output is correct |