#include "insects.h"
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2020;
int n, in[maxn], qtd[maxn], block[maxn], blockout[maxn];
int ids[maxn];
int diff = 1;
int cnt = 0;
int cur = 1;
int check(int mid) {
for(int i = 0; i < n; i++) {
if(in[i] || block[i]) continue;
move_inside(i); in[i] = 1; cnt++;
int qry = press_button();
if(qry > cur) {
qtd[i] = qry;
}
cur = qry;
if(cur > mid) {
move_outside(i); in[i] = 0; cnt--;
cur--;
}
}
if(mid*diff == cnt) {
return true;
}
return false;
}
int min_cardinality(int N) {
n = N;
int qtdN = n;
// First count the number of different numbers
move_inside(0); in[0] = 1; cnt++;
qtd[0] = 1;
for(int i = 1; i < n; i++) {
move_inside(i); in[i] = 1; cnt++;
qtd[i] = 1;
diff++;
int qry = press_button();
blockout[i] = 1;
if(qry == 2) {
diff--;
move_outside(i); in[i] = 0; cnt--;
qtd[i] = 2;
blockout[i] = 0;
}
}
if(diff == 1) return n;
if(diff == n) return 1;
int l = 1;
int r = min(n/2,(n+diff+1)/diff);
int ans = 1;
while(l <= r) {
int mid = max(l,(l+r)/2); // I want to see if the answer is <= mid
if(check(mid)) {
ans = mid;
l = mid+1;
// Everyone that is in will not be take off anymore
for(int i = 0; i < n; i++) {
if(in[i]) blockout[i] = 1;
}
}
else {
r = mid-1;
for(int i = 0; i < n; i++) {
if(!in[i]) {
block[i] = 1;
qtdN--;
}
if(in[i] && !blockout[i]) {
move_outside(i); in[i] = 0; cnt--;
}
}
cur = 0;
}
// r = min(r,qtdN/diff);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
3 ms |
208 KB |
Output is correct |
7 |
Correct |
2 ms |
208 KB |
Output is correct |
8 |
Correct |
5 ms |
208 KB |
Output is correct |
9 |
Correct |
7 ms |
208 KB |
Output is correct |
10 |
Correct |
5 ms |
208 KB |
Output is correct |
11 |
Correct |
4 ms |
312 KB |
Output is correct |
12 |
Correct |
5 ms |
316 KB |
Output is correct |
13 |
Correct |
5 ms |
208 KB |
Output is correct |
14 |
Correct |
4 ms |
208 KB |
Output is correct |
15 |
Correct |
5 ms |
336 KB |
Output is correct |
16 |
Correct |
5 ms |
208 KB |
Output is correct |
17 |
Correct |
5 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 |
6 ms |
320 KB |
Output is correct |
21 |
Correct |
4 ms |
312 KB |
Output is correct |
22 |
Correct |
2 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
3 ms |
208 KB |
Output is correct |
7 |
Correct |
2 ms |
208 KB |
Output is correct |
8 |
Correct |
5 ms |
208 KB |
Output is correct |
9 |
Correct |
7 ms |
208 KB |
Output is correct |
10 |
Correct |
5 ms |
208 KB |
Output is correct |
11 |
Correct |
4 ms |
312 KB |
Output is correct |
12 |
Correct |
5 ms |
316 KB |
Output is correct |
13 |
Correct |
5 ms |
208 KB |
Output is correct |
14 |
Correct |
4 ms |
208 KB |
Output is correct |
15 |
Correct |
5 ms |
336 KB |
Output is correct |
16 |
Correct |
5 ms |
208 KB |
Output is correct |
17 |
Correct |
5 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 |
6 ms |
320 KB |
Output is correct |
21 |
Correct |
4 ms |
312 KB |
Output is correct |
22 |
Correct |
2 ms |
208 KB |
Output is correct |
23 |
Correct |
10 ms |
208 KB |
Output is correct |
24 |
Correct |
9 ms |
208 KB |
Output is correct |
25 |
Correct |
21 ms |
208 KB |
Output is correct |
26 |
Correct |
13 ms |
312 KB |
Output is correct |
27 |
Correct |
21 ms |
316 KB |
Output is correct |
28 |
Correct |
21 ms |
208 KB |
Output is correct |
29 |
Correct |
29 ms |
316 KB |
Output is correct |
30 |
Correct |
24 ms |
208 KB |
Output is correct |
31 |
Correct |
30 ms |
308 KB |
Output is correct |
32 |
Correct |
29 ms |
312 KB |
Output is correct |
33 |
Correct |
23 ms |
436 KB |
Output is correct |
34 |
Correct |
28 ms |
208 KB |
Output is correct |
35 |
Correct |
24 ms |
328 KB |
Output is correct |
36 |
Correct |
24 ms |
312 KB |
Output is correct |
37 |
Correct |
23 ms |
208 KB |
Output is correct |
38 |
Correct |
21 ms |
316 KB |
Output is correct |
39 |
Correct |
20 ms |
316 KB |
Output is correct |
40 |
Correct |
15 ms |
208 KB |
Output is correct |
41 |
Correct |
16 ms |
304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
19 ms |
316 KB |
Output is correct |
8 |
Correct |
27 ms |
316 KB |
Output is correct |
9 |
Correct |
60 ms |
208 KB |
Output is correct |
10 |
Correct |
62 ms |
316 KB |
Output is correct |
11 |
Correct |
53 ms |
316 KB |
Output is correct |
12 |
Correct |
24 ms |
316 KB |
Output is correct |
13 |
Correct |
59 ms |
208 KB |
Output is correct |
14 |
Correct |
48 ms |
316 KB |
Output is correct |
15 |
Correct |
54 ms |
208 KB |
Output is correct |
16 |
Correct |
44 ms |
308 KB |
Output is correct |
17 |
Correct |
49 ms |
316 KB |
Output is correct |
18 |
Correct |
51 ms |
308 KB |
Output is correct |
19 |
Correct |
48 ms |
316 KB |
Output is correct |
20 |
Correct |
44 ms |
312 KB |
Output is correct |
21 |
Correct |
54 ms |
456 KB |
Output is correct |
22 |
Correct |
65 ms |
316 KB |
Output is correct |
23 |
Correct |
42 ms |
316 KB |
Output is correct |
24 |
Correct |
58 ms |
312 KB |
Output is correct |
25 |
Correct |
32 ms |
208 KB |
Output is correct |
26 |
Correct |
27 ms |
308 KB |
Output is correct |
27 |
Correct |
58 ms |
312 KB |
Output is correct |
28 |
Correct |
57 ms |
312 KB |
Output is correct |
29 |
Correct |
64 ms |
208 KB |
Output is correct |
30 |
Correct |
59 ms |
320 KB |
Output is correct |
31 |
Correct |
57 ms |
312 KB |
Output is correct |
32 |
Correct |
56 ms |
312 KB |
Output is correct |
33 |
Correct |
51 ms |
312 KB |
Output is correct |
34 |
Correct |
60 ms |
208 KB |
Output is correct |
35 |
Correct |
57 ms |
308 KB |
Output is correct |
36 |
Correct |
42 ms |
328 KB |
Output is correct |
37 |
Correct |
38 ms |
312 KB |
Output is correct |
38 |
Correct |
59 ms |
312 KB |
Output is correct |
39 |
Correct |
52 ms |
308 KB |
Output is correct |
40 |
Correct |
48 ms |
296 KB |
Output is correct |
41 |
Correct |
44 ms |
316 KB |
Output is correct |
42 |
Correct |
45 ms |
308 KB |
Output is correct |
43 |
Correct |
10 ms |
316 KB |
Output is correct |
44 |
Correct |
42 ms |
312 KB |
Output is correct |
45 |
Correct |
59 ms |
208 KB |
Output is correct |
46 |
Correct |
28 ms |
316 KB |
Output is correct |
47 |
Correct |
24 ms |
316 KB |
Output is correct |
48 |
Correct |
31 ms |
432 KB |
Output is correct |