#include "insects.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) begin(a), end(a)
using vi = vector<int>;
using ll = long long;
using ar2 = array<ll,2>;
using ar3 = array<ll,3>;
const int mxN = (int)2e3+10;
int n, cnt[mxN];
vi v, others;
set<int> S;
map<set<int>,int> M;
void move_in(int i){
if(S.count(i)) return;
S.insert(i); move_inside(i);
}
void move_out(int i){
if(!S.count(i)) return;
S.erase(i); move_outside(i);
}
int press(){
if(sz(S)==1) return 1;
if(M.count(S)) return M[S];
return M[S] = press_button();
}
int min_cardinality(int N) {
n = N; int ans = n, D=n;
vector<int> xd(n,0); iota(all(xd),0);
random_shuffle(all(xd));
for(int i = 0; i < n; i++){
move_in(xd[i]);
if(press()==2) move_out(xd[i]), D--;
}
int l = 1, r = n;
while(l<r){
int mid = (l+r+1)/2, tot=0;
for(int i = 0; i < n; i++) move_out(xd[i]);
for(int i = 0; i < n; i++){
move_in(xd[i]); tot++;
if(press()>mid) move_out(xd[i]), tot--;
}
if(tot==D*mid) l=mid;
else r=mid-1;
}
return l;
}
Compilation message
insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:34:13: warning: unused variable 'ans' [-Wunused-variable]
34 | n = N; int ans = n, D=n;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 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 |
11 ms |
2436 KB |
Output is correct |
7 |
Correct |
9 ms |
1368 KB |
Output is correct |
8 |
Correct |
12 ms |
1880 KB |
Output is correct |
9 |
Correct |
13 ms |
3888 KB |
Output is correct |
10 |
Correct |
9 ms |
2136 KB |
Output is correct |
11 |
Correct |
16 ms |
4952 KB |
Output is correct |
12 |
Correct |
16 ms |
2904 KB |
Output is correct |
13 |
Correct |
11 ms |
3160 KB |
Output is correct |
14 |
Correct |
12 ms |
3672 KB |
Output is correct |
15 |
Correct |
18 ms |
4688 KB |
Output is correct |
16 |
Correct |
14 ms |
4996 KB |
Output is correct |
17 |
Correct |
15 ms |
3660 KB |
Output is correct |
18 |
Correct |
13 ms |
3672 KB |
Output is correct |
19 |
Correct |
13 ms |
4440 KB |
Output is correct |
20 |
Correct |
11 ms |
3284 KB |
Output is correct |
21 |
Correct |
13 ms |
3412 KB |
Output is correct |
22 |
Correct |
15 ms |
2904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 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 |
11 ms |
2436 KB |
Output is correct |
7 |
Correct |
9 ms |
1368 KB |
Output is correct |
8 |
Correct |
12 ms |
1880 KB |
Output is correct |
9 |
Correct |
13 ms |
3888 KB |
Output is correct |
10 |
Correct |
9 ms |
2136 KB |
Output is correct |
11 |
Correct |
16 ms |
4952 KB |
Output is correct |
12 |
Correct |
16 ms |
2904 KB |
Output is correct |
13 |
Correct |
11 ms |
3160 KB |
Output is correct |
14 |
Correct |
12 ms |
3672 KB |
Output is correct |
15 |
Correct |
18 ms |
4688 KB |
Output is correct |
16 |
Correct |
14 ms |
4996 KB |
Output is correct |
17 |
Correct |
15 ms |
3660 KB |
Output is correct |
18 |
Correct |
13 ms |
3672 KB |
Output is correct |
19 |
Correct |
13 ms |
4440 KB |
Output is correct |
20 |
Correct |
11 ms |
3284 KB |
Output is correct |
21 |
Correct |
13 ms |
3412 KB |
Output is correct |
22 |
Correct |
15 ms |
2904 KB |
Output is correct |
23 |
Correct |
383 ms |
54904 KB |
Output is correct |
24 |
Correct |
320 ms |
23888 KB |
Output is correct |
25 |
Correct |
321 ms |
27212 KB |
Output is correct |
26 |
Correct |
360 ms |
118444 KB |
Output is correct |
27 |
Correct |
150 ms |
38952 KB |
Output is correct |
28 |
Correct |
330 ms |
141076 KB |
Output is correct |
29 |
Correct |
226 ms |
58108 KB |
Output is correct |
30 |
Correct |
270 ms |
61692 KB |
Output is correct |
31 |
Correct |
427 ms |
94544 KB |
Output is correct |
32 |
Correct |
355 ms |
98872 KB |
Output is correct |
33 |
Correct |
393 ms |
93992 KB |
Output is correct |
34 |
Correct |
371 ms |
87160 KB |
Output is correct |
35 |
Correct |
388 ms |
103764 KB |
Output is correct |
36 |
Correct |
360 ms |
108360 KB |
Output is correct |
37 |
Correct |
348 ms |
103968 KB |
Output is correct |
38 |
Correct |
340 ms |
84536 KB |
Output is correct |
39 |
Correct |
362 ms |
77832 KB |
Output is correct |
40 |
Correct |
357 ms |
76752 KB |
Output is correct |
41 |
Correct |
323 ms |
79100 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 |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Partially correct |
0 ms |
344 KB |
Output is partially correct |
7 |
Execution timed out |
2249 ms |
218948 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |