#include "insects.h"
#include <bits/stdc++.h>
using namespace std;
int n;
bool used[2000],check[2000][2];
int mySolve[2001];
int solve(int x) {
int& ret = mySolve[x];
if (ret != -1)
return ret;
ret = 0;
for (int i = 0; i < n; i++) {
if (!check[i][0] && !check[i][1]) {
move_inside(i);
used[i] = true;
if (press_button() > x) {
used[i] = false;
move_outside(i);
}
}
if (used[i])
ret++;
}
return ret;
}
int min_cardinality(int _n) {
n = _n;
memset(mySolve, -1, sizeof(mySolve));
int cnt = solve(1);
int l = 1, r = n / cnt, ans;
while (l <= r) {
int m = (l + r) >> 1;
if (solve(m) == cnt * m) {
for (int i = 0; i < n; i++) {
if (used[i])
check[i][0] = true;
}
ans = m;
l = m + 1;
}
else {
for (int i = 0; i < n; i++) {
if (!used[i])
check[i][1] = true;
if (used[i] && !check[i][0]) {
used[i] = false;
move_outside(i);
}
}
r = m - 1;
}
}
return ans;
}
Compilation message
insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:53:9: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
53 | return ans;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
6 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 |
7 ms |
208 KB |
Output is correct |
11 |
Correct |
2 ms |
208 KB |
Output is correct |
12 |
Correct |
6 ms |
208 KB |
Output is correct |
13 |
Correct |
4 ms |
208 KB |
Output is correct |
14 |
Correct |
4 ms |
208 KB |
Output is correct |
15 |
Correct |
7 ms |
208 KB |
Output is correct |
16 |
Correct |
4 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 |
4 ms |
208 KB |
Output is correct |
21 |
Correct |
2 ms |
208 KB |
Output is correct |
22 |
Correct |
3 ms |
208 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 |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
6 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 |
7 ms |
208 KB |
Output is correct |
11 |
Correct |
2 ms |
208 KB |
Output is correct |
12 |
Correct |
6 ms |
208 KB |
Output is correct |
13 |
Correct |
4 ms |
208 KB |
Output is correct |
14 |
Correct |
4 ms |
208 KB |
Output is correct |
15 |
Correct |
7 ms |
208 KB |
Output is correct |
16 |
Correct |
4 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 |
4 ms |
208 KB |
Output is correct |
21 |
Correct |
2 ms |
208 KB |
Output is correct |
22 |
Correct |
3 ms |
208 KB |
Output is correct |
23 |
Correct |
27 ms |
208 KB |
Output is correct |
24 |
Correct |
9 ms |
208 KB |
Output is correct |
25 |
Correct |
33 ms |
208 KB |
Output is correct |
26 |
Correct |
20 ms |
208 KB |
Output is correct |
27 |
Correct |
21 ms |
208 KB |
Output is correct |
28 |
Correct |
11 ms |
208 KB |
Output is correct |
29 |
Correct |
24 ms |
208 KB |
Output is correct |
30 |
Correct |
22 ms |
208 KB |
Output is correct |
31 |
Correct |
32 ms |
208 KB |
Output is correct |
32 |
Correct |
23 ms |
208 KB |
Output is correct |
33 |
Correct |
35 ms |
208 KB |
Output is correct |
34 |
Correct |
29 ms |
208 KB |
Output is correct |
35 |
Correct |
24 ms |
208 KB |
Output is correct |
36 |
Correct |
17 ms |
208 KB |
Output is correct |
37 |
Correct |
24 ms |
208 KB |
Output is correct |
38 |
Correct |
40 ms |
208 KB |
Output is correct |
39 |
Correct |
20 ms |
208 KB |
Output is correct |
40 |
Correct |
15 ms |
208 KB |
Output is correct |
41 |
Correct |
10 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
272 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
54 ms |
208 KB |
Output is correct |
8 |
Correct |
17 ms |
208 KB |
Output is correct |
9 |
Correct |
30 ms |
208 KB |
Output is correct |
10 |
Correct |
55 ms |
208 KB |
Output is correct |
11 |
Correct |
56 ms |
208 KB |
Output is correct |
12 |
Correct |
32 ms |
208 KB |
Output is correct |
13 |
Correct |
35 ms |
208 KB |
Output is correct |
14 |
Correct |
53 ms |
208 KB |
Output is correct |
15 |
Correct |
59 ms |
208 KB |
Output is correct |
16 |
Correct |
30 ms |
208 KB |
Output is correct |
17 |
Correct |
67 ms |
208 KB |
Output is correct |
18 |
Correct |
28 ms |
208 KB |
Output is correct |
19 |
Partially correct |
44 ms |
208 KB |
Output is partially correct |
20 |
Correct |
75 ms |
208 KB |
Output is correct |
21 |
Correct |
55 ms |
308 KB |
Output is correct |
22 |
Correct |
46 ms |
296 KB |
Output is correct |
23 |
Correct |
51 ms |
208 KB |
Output is correct |
24 |
Correct |
29 ms |
308 KB |
Output is correct |
25 |
Correct |
23 ms |
208 KB |
Output is correct |
26 |
Correct |
14 ms |
208 KB |
Output is correct |
27 |
Partially correct |
52 ms |
208 KB |
Output is partially correct |
28 |
Partially correct |
55 ms |
208 KB |
Output is partially correct |
29 |
Partially correct |
46 ms |
208 KB |
Output is partially correct |
30 |
Partially correct |
57 ms |
208 KB |
Output is partially correct |
31 |
Correct |
64 ms |
208 KB |
Output is correct |
32 |
Correct |
57 ms |
208 KB |
Output is correct |
33 |
Correct |
54 ms |
296 KB |
Output is correct |
34 |
Correct |
78 ms |
296 KB |
Output is correct |
35 |
Partially correct |
54 ms |
208 KB |
Output is partially correct |
36 |
Partially correct |
54 ms |
208 KB |
Output is partially correct |
37 |
Correct |
50 ms |
304 KB |
Output is correct |
38 |
Correct |
55 ms |
296 KB |
Output is correct |
39 |
Partially correct |
65 ms |
208 KB |
Output is partially correct |
40 |
Partially correct |
64 ms |
208 KB |
Output is partially correct |
41 |
Partially correct |
46 ms |
208 KB |
Output is partially correct |
42 |
Partially correct |
65 ms |
208 KB |
Output is partially correct |
43 |
Correct |
15 ms |
208 KB |
Output is correct |
44 |
Correct |
41 ms |
208 KB |
Output is correct |
45 |
Correct |
60 ms |
208 KB |
Output is correct |
46 |
Correct |
27 ms |
208 KB |
Output is correct |
47 |
Correct |
34 ms |
208 KB |
Output is correct |
48 |
Correct |
42 ms |
208 KB |
Output is correct |