#include"insects.h"
#include<bits/stdc++.h>
using namespace std;
int min_cardinality(int N) {
int k, diff = 0;
set<int> in;
for(int i = 0; i < N; ++i) {
in.insert(i);
move_inside(i);
k = press_button();
if(k == 2) {
in.erase(i);
move_outside(i);
continue;
}
diff++;
}
int l = 1, r = N / diff;
vector<bool> skp(N);
while(l < r) {
int mid = (l + r + 1) / 2;
vector<int> lst_added, ws;
for(int i = 0; i < N; ++i) {
if(skp[i] || !in.insert(i).second) continue;
move_inside(i);
k = press_button();
if(k > mid) {
in.erase(i);
move_outside(i);
ws.push_back(i);
continue;
}
lst_added.push_back(i);
if(diff * mid == (int)in.size()) break;
}
if((int)in.size() < diff * mid) {
r = mid - 1;
if(l == r) continue;
for(auto& u : lst_added) {
in.erase(u);
move_outside(u);
}
for(auto& u : ws) skp[u] = 1;
} else l = mid;
}
return (l + r) / 2;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
2 ms |
600 KB |
Output is correct |
10 |
Correct |
2 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
432 KB |
Output is correct |
12 |
Correct |
3 ms |
600 KB |
Output is correct |
13 |
Correct |
2 ms |
604 KB |
Output is correct |
14 |
Correct |
2 ms |
600 KB |
Output is correct |
15 |
Correct |
2 ms |
344 KB |
Output is correct |
16 |
Correct |
2 ms |
600 KB |
Output is correct |
17 |
Correct |
3 ms |
600 KB |
Output is correct |
18 |
Correct |
2 ms |
600 KB |
Output is correct |
19 |
Correct |
2 ms |
344 KB |
Output is correct |
20 |
Correct |
2 ms |
600 KB |
Output is correct |
21 |
Correct |
2 ms |
600 KB |
Output is correct |
22 |
Correct |
1 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
2 ms |
600 KB |
Output is correct |
10 |
Correct |
2 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
432 KB |
Output is correct |
12 |
Correct |
3 ms |
600 KB |
Output is correct |
13 |
Correct |
2 ms |
604 KB |
Output is correct |
14 |
Correct |
2 ms |
600 KB |
Output is correct |
15 |
Correct |
2 ms |
344 KB |
Output is correct |
16 |
Correct |
2 ms |
600 KB |
Output is correct |
17 |
Correct |
3 ms |
600 KB |
Output is correct |
18 |
Correct |
2 ms |
600 KB |
Output is correct |
19 |
Correct |
2 ms |
344 KB |
Output is correct |
20 |
Correct |
2 ms |
600 KB |
Output is correct |
21 |
Correct |
2 ms |
600 KB |
Output is correct |
22 |
Correct |
1 ms |
600 KB |
Output is correct |
23 |
Correct |
11 ms |
432 KB |
Output is correct |
24 |
Correct |
5 ms |
712 KB |
Output is correct |
25 |
Correct |
11 ms |
868 KB |
Output is correct |
26 |
Correct |
13 ms |
716 KB |
Output is correct |
27 |
Correct |
15 ms |
600 KB |
Output is correct |
28 |
Correct |
4 ms |
1112 KB |
Output is correct |
29 |
Correct |
13 ms |
600 KB |
Output is correct |
30 |
Correct |
11 ms |
600 KB |
Output is correct |
31 |
Correct |
10 ms |
940 KB |
Output is correct |
32 |
Correct |
11 ms |
848 KB |
Output is correct |
33 |
Correct |
16 ms |
880 KB |
Output is correct |
34 |
Correct |
12 ms |
440 KB |
Output is correct |
35 |
Correct |
14 ms |
616 KB |
Output is correct |
36 |
Correct |
12 ms |
1120 KB |
Output is correct |
37 |
Correct |
13 ms |
856 KB |
Output is correct |
38 |
Correct |
10 ms |
600 KB |
Output is correct |
39 |
Correct |
9 ms |
856 KB |
Output is correct |
40 |
Correct |
8 ms |
1112 KB |
Output is correct |
41 |
Correct |
4 ms |
696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
28 ms |
412 KB |
Output is correct |
8 |
Correct |
8 ms |
1208 KB |
Output is correct |
9 |
Correct |
21 ms |
1104 KB |
Output is correct |
10 |
Correct |
24 ms |
600 KB |
Output is correct |
11 |
Correct |
23 ms |
620 KB |
Output is correct |
12 |
Correct |
14 ms |
856 KB |
Output is correct |
13 |
Correct |
26 ms |
848 KB |
Output is correct |
14 |
Correct |
23 ms |
1124 KB |
Output is correct |
15 |
Correct |
19 ms |
1392 KB |
Output is correct |
16 |
Correct |
20 ms |
932 KB |
Output is correct |
17 |
Correct |
21 ms |
1148 KB |
Output is correct |
18 |
Correct |
25 ms |
980 KB |
Output is correct |
19 |
Correct |
25 ms |
700 KB |
Output is correct |
20 |
Correct |
28 ms |
1616 KB |
Output is correct |
21 |
Correct |
27 ms |
848 KB |
Output is correct |
22 |
Correct |
26 ms |
676 KB |
Output is correct |
23 |
Correct |
25 ms |
860 KB |
Output is correct |
24 |
Correct |
17 ms |
888 KB |
Output is correct |
25 |
Correct |
13 ms |
856 KB |
Output is correct |
26 |
Correct |
12 ms |
856 KB |
Output is correct |
27 |
Correct |
27 ms |
744 KB |
Output is correct |
28 |
Correct |
17 ms |
1144 KB |
Output is correct |
29 |
Correct |
28 ms |
1360 KB |
Output is correct |
30 |
Correct |
25 ms |
916 KB |
Output is correct |
31 |
Correct |
30 ms |
1180 KB |
Output is correct |
32 |
Correct |
26 ms |
696 KB |
Output is correct |
33 |
Correct |
25 ms |
1180 KB |
Output is correct |
34 |
Correct |
26 ms |
476 KB |
Output is correct |
35 |
Partially correct |
30 ms |
848 KB |
Output is partially correct |
36 |
Correct |
26 ms |
1104 KB |
Output is correct |
37 |
Correct |
26 ms |
1480 KB |
Output is correct |
38 |
Correct |
28 ms |
712 KB |
Output is correct |
39 |
Correct |
26 ms |
1104 KB |
Output is correct |
40 |
Correct |
16 ms |
848 KB |
Output is correct |
41 |
Correct |
24 ms |
1456 KB |
Output is correct |
42 |
Partially correct |
28 ms |
1664 KB |
Output is partially correct |
43 |
Correct |
6 ms |
600 KB |
Output is correct |
44 |
Correct |
20 ms |
692 KB |
Output is correct |
45 |
Correct |
19 ms |
676 KB |
Output is correct |
46 |
Correct |
12 ms |
1192 KB |
Output is correct |
47 |
Correct |
17 ms |
896 KB |
Output is correct |
48 |
Correct |
17 ms |
648 KB |
Output is correct |