#include "insects.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define INF 1e18
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define OK cout<<"Ok"<<endl;
#define MOD (ll)(1e9+7)
#define endl "\n"
const int mxn=2e3+5;
int sz,n,cnt,color[mxn],color2[mxn];
set<int>ST;
bool check(int k){
if(k==1) return 1;
set<int>st;
st=ST;
vector<int>vt;
for(int i=0;i<n;i++){
vt.pb(i);
}
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
shuffle(vt.begin(),vt.end(),default_random_engine(seed));
memset(color2,0,sizeof(color2));
for(int id=0;id<n;id++){
int i=vt[id];
if(color[i]) continue;
if(st.count(i)) continue;
if(st.size()==cnt*k) break;
move_inside(i);
st.insert(i);
if(press_button()>k){
st.erase(i);
color2[i]=1;
move_outside(i);
}
}
if(st.size()==cnt*k){
ST=st;
return 1;
}
else{
for(int i=0;i<n;i++){
if(!st.count(i)){
color[i]=1;
}
}
for(auto x:st){
if(!ST.count(x)){
move_outside(x);
}
}
return 0;
}
}
int min_cardinality(int N) {
n=N;
set<int>st;
for(int i=0;i<n;i++){
move_inside(i);
cnt++;
st.insert(i);
if(press_button()>1){
move_outside(i);
st.erase(i);
cnt--;
}
}
for(auto x:st){
move_outside(x);
}
if(cnt==1) return n;
if(cnt==n) return 1;
if(cnt>n/2) return 1;
int l=1,r=n/cnt;
while(l<=r){
int m=(l+r)/2;
if(check(m)){
l=m+1;
}
else{
r=m-1;
}
}
return l-1;
}
Compilation message
insects.cpp: In function 'bool check(int)':
insects.cpp:34:21: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
34 | if(st.size()==cnt*k) break;
| ~~~~~~~~~^~~~~~~
insects.cpp:43:17: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
43 | if(st.size()==cnt*k){
| ~~~~~~~~~^~~~~~~
# |
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 |
2 ms |
208 KB |
Output is correct |
7 |
Correct |
2 ms |
208 KB |
Output is correct |
8 |
Correct |
4 ms |
332 KB |
Output is correct |
9 |
Correct |
6 ms |
320 KB |
Output is correct |
10 |
Correct |
5 ms |
208 KB |
Output is correct |
11 |
Correct |
2 ms |
208 KB |
Output is correct |
12 |
Correct |
4 ms |
304 KB |
Output is correct |
13 |
Correct |
5 ms |
208 KB |
Output is correct |
14 |
Correct |
2 ms |
300 KB |
Output is correct |
15 |
Correct |
4 ms |
208 KB |
Output is correct |
16 |
Correct |
4 ms |
208 KB |
Output is correct |
17 |
Correct |
3 ms |
300 KB |
Output is correct |
18 |
Correct |
4 ms |
208 KB |
Output is correct |
19 |
Correct |
5 ms |
308 KB |
Output is correct |
20 |
Correct |
4 ms |
208 KB |
Output is correct |
21 |
Correct |
3 ms |
308 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 |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
2 ms |
208 KB |
Output is correct |
7 |
Correct |
2 ms |
208 KB |
Output is correct |
8 |
Correct |
4 ms |
332 KB |
Output is correct |
9 |
Correct |
6 ms |
320 KB |
Output is correct |
10 |
Correct |
5 ms |
208 KB |
Output is correct |
11 |
Correct |
2 ms |
208 KB |
Output is correct |
12 |
Correct |
4 ms |
304 KB |
Output is correct |
13 |
Correct |
5 ms |
208 KB |
Output is correct |
14 |
Correct |
2 ms |
300 KB |
Output is correct |
15 |
Correct |
4 ms |
208 KB |
Output is correct |
16 |
Correct |
4 ms |
208 KB |
Output is correct |
17 |
Correct |
3 ms |
300 KB |
Output is correct |
18 |
Correct |
4 ms |
208 KB |
Output is correct |
19 |
Correct |
5 ms |
308 KB |
Output is correct |
20 |
Correct |
4 ms |
208 KB |
Output is correct |
21 |
Correct |
3 ms |
308 KB |
Output is correct |
22 |
Correct |
2 ms |
208 KB |
Output is correct |
23 |
Correct |
9 ms |
208 KB |
Output is correct |
24 |
Correct |
9 ms |
336 KB |
Output is correct |
25 |
Correct |
16 ms |
320 KB |
Output is correct |
26 |
Correct |
23 ms |
356 KB |
Output is correct |
27 |
Correct |
18 ms |
304 KB |
Output is correct |
28 |
Correct |
9 ms |
316 KB |
Output is correct |
29 |
Correct |
21 ms |
308 KB |
Output is correct |
30 |
Correct |
21 ms |
292 KB |
Output is correct |
31 |
Correct |
21 ms |
304 KB |
Output is correct |
32 |
Correct |
21 ms |
376 KB |
Output is correct |
33 |
Correct |
21 ms |
296 KB |
Output is correct |
34 |
Correct |
20 ms |
376 KB |
Output is correct |
35 |
Correct |
16 ms |
300 KB |
Output is correct |
36 |
Correct |
22 ms |
356 KB |
Output is correct |
37 |
Correct |
13 ms |
324 KB |
Output is correct |
38 |
Correct |
17 ms |
324 KB |
Output is correct |
39 |
Correct |
20 ms |
312 KB |
Output is correct |
40 |
Correct |
17 ms |
336 KB |
Output is correct |
41 |
Correct |
8 ms |
320 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 |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
9 ms |
208 KB |
Output is correct |
8 |
Correct |
11 ms |
340 KB |
Output is correct |
9 |
Correct |
44 ms |
416 KB |
Output is correct |
10 |
Correct |
46 ms |
328 KB |
Output is correct |
11 |
Correct |
44 ms |
296 KB |
Output is correct |
12 |
Correct |
16 ms |
368 KB |
Output is correct |
13 |
Correct |
49 ms |
300 KB |
Output is correct |
14 |
Correct |
48 ms |
288 KB |
Output is correct |
15 |
Correct |
39 ms |
412 KB |
Output is correct |
16 |
Correct |
31 ms |
448 KB |
Output is correct |
17 |
Correct |
24 ms |
420 KB |
Output is correct |
18 |
Correct |
38 ms |
408 KB |
Output is correct |
19 |
Correct |
47 ms |
468 KB |
Output is correct |
20 |
Correct |
43 ms |
440 KB |
Output is correct |
21 |
Correct |
25 ms |
328 KB |
Output is correct |
22 |
Correct |
52 ms |
328 KB |
Output is correct |
23 |
Correct |
33 ms |
304 KB |
Output is correct |
24 |
Correct |
38 ms |
308 KB |
Output is correct |
25 |
Correct |
33 ms |
408 KB |
Output is correct |
26 |
Correct |
13 ms |
336 KB |
Output is correct |
27 |
Correct |
35 ms |
476 KB |
Output is correct |
28 |
Correct |
38 ms |
428 KB |
Output is correct |
29 |
Correct |
43 ms |
412 KB |
Output is correct |
30 |
Correct |
41 ms |
404 KB |
Output is correct |
31 |
Correct |
51 ms |
420 KB |
Output is correct |
32 |
Correct |
28 ms |
364 KB |
Output is correct |
33 |
Correct |
39 ms |
300 KB |
Output is correct |
34 |
Correct |
38 ms |
296 KB |
Output is correct |
35 |
Correct |
35 ms |
472 KB |
Output is correct |
36 |
Correct |
40 ms |
448 KB |
Output is correct |
37 |
Correct |
51 ms |
412 KB |
Output is correct |
38 |
Correct |
49 ms |
412 KB |
Output is correct |
39 |
Correct |
35 ms |
456 KB |
Output is correct |
40 |
Correct |
36 ms |
428 KB |
Output is correct |
41 |
Correct |
41 ms |
416 KB |
Output is correct |
42 |
Correct |
38 ms |
456 KB |
Output is correct |
43 |
Correct |
10 ms |
320 KB |
Output is correct |
44 |
Correct |
33 ms |
284 KB |
Output is correct |
45 |
Correct |
31 ms |
408 KB |
Output is correct |
46 |
Correct |
34 ms |
328 KB |
Output is correct |
47 |
Correct |
30 ms |
328 KB |
Output is correct |
48 |
Correct |
33 ms |
300 KB |
Output is correct |