#include "insects.h"
#include<bits/stdc++.h>
using namespace std;
#define in move_inside
#define press press_button
#define out move_outside
set<int> mp,mp2,mp3;
int n,p;
bool check(int k1){
stack<int> st;
for(int i=0;i<n;++i){
if(mp.size()==p*k1) break;
if(mp.count(i)) continue;
if(mp3.count(i)) continue;
in(i);
if(press()>k1) out(i);
else mp.insert(i),st.push(i);
}
if(mp.size()==p*k1){
for(auto &e:mp) if(mp2.count(e)) mp2.erase(e);
return 1;
}
stack<int> st2;
for(auto &e:mp2){
if(!mp.count(e)) st2.push(e);
}
while(!st2.empty()){
mp2.erase(st2.top());
mp3.insert(st2.top());
st2.pop();
}
while(st.size()){
mp.erase(st.top());
out(st.top());
st.pop();
}
return 0;
}
int min_cardinality(int N){
n=N;
for(int i=0;i<n;++i){
in(i);
if(press()>1) out(i),mp2.insert(i);
else mp.insert(i);
}
p=mp.size();
int l=1,r=n/p;
while(l<r){
if(r==l+1){
if(check(r)) return r;
return l;
}
if(r==l+2){
if(check(r)) return r;
if(check(l+1)) return l+1;
return l;
}
int sz=(r-l)/3;
int mid1=l+sz;
int mid2=r-sz;
if(check(mid2)) l=mid2;
else if(check(mid1)) l=mid1,r=mid2-1;
else r=mid1-1;
}
return l;
}
Compilation message
insects.cpp: In function 'bool check(int)':
insects.cpp:16:21: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
16 | if(mp.size()==p*k1) break;
| ~~~~~~~~~^~~~~~
insects.cpp:23:17: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
23 | if(mp.size()==p*k1){
| ~~~~~~~~~^~~~~~
# |
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 |
404 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 |
600 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
2 ms |
600 KB |
Output is correct |
9 |
Correct |
3 ms |
600 KB |
Output is correct |
10 |
Correct |
2 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
3 ms |
856 KB |
Output is correct |
13 |
Correct |
3 ms |
344 KB |
Output is correct |
14 |
Correct |
3 ms |
448 KB |
Output is correct |
15 |
Correct |
2 ms |
600 KB |
Output is correct |
16 |
Correct |
2 ms |
444 KB |
Output is correct |
17 |
Correct |
2 ms |
600 KB |
Output is correct |
18 |
Correct |
3 ms |
600 KB |
Output is correct |
19 |
Correct |
3 ms |
600 KB |
Output is correct |
20 |
Correct |
2 ms |
692 KB |
Output is correct |
21 |
Correct |
2 ms |
600 KB |
Output is correct |
22 |
Correct |
1 ms |
600 KB |
Output is correct |
# |
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 |
404 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 |
600 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
2 ms |
600 KB |
Output is correct |
9 |
Correct |
3 ms |
600 KB |
Output is correct |
10 |
Correct |
2 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
3 ms |
856 KB |
Output is correct |
13 |
Correct |
3 ms |
344 KB |
Output is correct |
14 |
Correct |
3 ms |
448 KB |
Output is correct |
15 |
Correct |
2 ms |
600 KB |
Output is correct |
16 |
Correct |
2 ms |
444 KB |
Output is correct |
17 |
Correct |
2 ms |
600 KB |
Output is correct |
18 |
Correct |
3 ms |
600 KB |
Output is correct |
19 |
Correct |
3 ms |
600 KB |
Output is correct |
20 |
Correct |
2 ms |
692 KB |
Output is correct |
21 |
Correct |
2 ms |
600 KB |
Output is correct |
22 |
Correct |
1 ms |
600 KB |
Output is correct |
23 |
Correct |
9 ms |
984 KB |
Output is correct |
24 |
Correct |
4 ms |
964 KB |
Output is correct |
25 |
Correct |
10 ms |
856 KB |
Output is correct |
26 |
Correct |
15 ms |
1624 KB |
Output is correct |
27 |
Correct |
11 ms |
712 KB |
Output is correct |
28 |
Correct |
4 ms |
868 KB |
Output is correct |
29 |
Correct |
17 ms |
712 KB |
Output is correct |
30 |
Correct |
13 ms |
1008 KB |
Output is correct |
31 |
Correct |
11 ms |
636 KB |
Output is correct |
32 |
Correct |
12 ms |
1384 KB |
Output is correct |
33 |
Correct |
15 ms |
888 KB |
Output is correct |
34 |
Correct |
14 ms |
1232 KB |
Output is correct |
35 |
Correct |
11 ms |
1112 KB |
Output is correct |
36 |
Correct |
12 ms |
1208 KB |
Output is correct |
37 |
Correct |
14 ms |
648 KB |
Output is correct |
38 |
Correct |
13 ms |
600 KB |
Output is correct |
39 |
Correct |
11 ms |
856 KB |
Output is correct |
40 |
Correct |
7 ms |
1460 KB |
Output is correct |
41 |
Correct |
4 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
368 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
21 ms |
1816 KB |
Output is correct |
8 |
Correct |
10 ms |
976 KB |
Output is correct |
9 |
Correct |
22 ms |
696 KB |
Output is correct |
10 |
Partially correct |
36 ms |
1504 KB |
Output is partially correct |
11 |
Correct |
25 ms |
1104 KB |
Output is correct |
12 |
Correct |
15 ms |
1112 KB |
Output is correct |
13 |
Partially correct |
41 ms |
1112 KB |
Output is partially correct |
14 |
Partially correct |
32 ms |
1352 KB |
Output is partially correct |
15 |
Correct |
26 ms |
1384 KB |
Output is correct |
16 |
Correct |
25 ms |
1240 KB |
Output is correct |
17 |
Correct |
26 ms |
1112 KB |
Output is correct |
18 |
Correct |
24 ms |
1052 KB |
Output is correct |
19 |
Correct |
25 ms |
988 KB |
Output is correct |
20 |
Correct |
21 ms |
1204 KB |
Output is correct |
21 |
Partially correct |
30 ms |
1280 KB |
Output is partially correct |
22 |
Partially correct |
34 ms |
756 KB |
Output is partially correct |
23 |
Correct |
35 ms |
600 KB |
Output is correct |
24 |
Correct |
22 ms |
1528 KB |
Output is correct |
25 |
Correct |
17 ms |
1648 KB |
Output is correct |
26 |
Correct |
8 ms |
1128 KB |
Output is correct |
27 |
Correct |
26 ms |
600 KB |
Output is correct |
28 |
Correct |
17 ms |
1216 KB |
Output is correct |
29 |
Correct |
23 ms |
1128 KB |
Output is correct |
30 |
Correct |
20 ms |
1276 KB |
Output is correct |
31 |
Partially correct |
31 ms |
1672 KB |
Output is partially correct |
32 |
Partially correct |
37 ms |
1516 KB |
Output is partially correct |
33 |
Partially correct |
35 ms |
1256 KB |
Output is partially correct |
34 |
Partially correct |
29 ms |
1396 KB |
Output is partially correct |
35 |
Correct |
23 ms |
1764 KB |
Output is correct |
36 |
Correct |
22 ms |
1112 KB |
Output is correct |
37 |
Partially correct |
28 ms |
1712 KB |
Output is partially correct |
38 |
Partially correct |
30 ms |
1364 KB |
Output is partially correct |
39 |
Correct |
20 ms |
1112 KB |
Output is correct |
40 |
Correct |
19 ms |
856 KB |
Output is correct |
41 |
Correct |
22 ms |
1252 KB |
Output is correct |
42 |
Correct |
22 ms |
1740 KB |
Output is correct |
43 |
Correct |
8 ms |
1124 KB |
Output is correct |
44 |
Correct |
25 ms |
772 KB |
Output is correct |
45 |
Correct |
22 ms |
1368 KB |
Output is correct |
46 |
Correct |
13 ms |
1412 KB |
Output is correct |
47 |
Correct |
13 ms |
1368 KB |
Output is correct |
48 |
Correct |
13 ms |
692 KB |
Output is correct |