#include "insects.h"
#include<bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
const int maxn = 2005;
int n, D, step;
int vis[maxn];
int forb[maxn];
vector<ii> in;
vector<int> p;
int check(int x) {
int y = -1, lst = 0;
for(int i : p) {
if(vis[i] || forb[i]) continue;
move_inside(i);
int cnt = press_button();
if(lst < x && cnt == x) y = i;
if(cnt > x)
move_outside(i), forb[i] = 1;
else in.pb({i, step}), vis[i] = 1;
if((int)in.size() == x * D) return 1;
lst = cnt;
}
if(y != -1) forb[y] = 1;
return 0;
}
int min_cardinality(int N) {
srand(time(0));
n = N, D = 0, step = 1;
for(int i = 0;i < n;i++) p.pb(i);
random_shuffle(all(p));
for(int i : p) {
move_inside(i);
if(press_button() > 1)
move_outside(i);
else in.pb({i, step}), vis[i] = 1, D++;
}
int lo = 1, hi = n / D, ans = 1;
while(lo <= hi) {
step++;
int mid = (lo + hi) / 2;
int flag = check(mid);
if(flag) {
ans = mid, lo = mid + 1;
for(int i = 0;i < n;i++) forb[i] = 0;
} else {
hi = mid - 1;
while(in.back().y == step)
move_outside(in.back().x), vis[in.back().x] = 0, in.pop_back();
}
}
return ans;
}
# |
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 |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
0 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 |
5 ms |
208 KB |
Output is correct |
10 |
Correct |
5 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 |
7 ms |
208 KB |
Output is correct |
14 |
Correct |
5 ms |
208 KB |
Output is correct |
15 |
Correct |
2 ms |
208 KB |
Output is correct |
16 |
Correct |
4 ms |
208 KB |
Output is correct |
17 |
Correct |
4 ms |
208 KB |
Output is correct |
18 |
Correct |
3 ms |
208 KB |
Output is correct |
19 |
Correct |
4 ms |
208 KB |
Output is correct |
20 |
Correct |
2 ms |
208 KB |
Output is correct |
21 |
Correct |
3 ms |
208 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 |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
0 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 |
5 ms |
208 KB |
Output is correct |
10 |
Correct |
5 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 |
7 ms |
208 KB |
Output is correct |
14 |
Correct |
5 ms |
208 KB |
Output is correct |
15 |
Correct |
2 ms |
208 KB |
Output is correct |
16 |
Correct |
4 ms |
208 KB |
Output is correct |
17 |
Correct |
4 ms |
208 KB |
Output is correct |
18 |
Correct |
3 ms |
208 KB |
Output is correct |
19 |
Correct |
4 ms |
208 KB |
Output is correct |
20 |
Correct |
2 ms |
208 KB |
Output is correct |
21 |
Correct |
3 ms |
208 KB |
Output is correct |
22 |
Correct |
2 ms |
208 KB |
Output is correct |
23 |
Correct |
12 ms |
300 KB |
Output is correct |
24 |
Correct |
7 ms |
320 KB |
Output is correct |
25 |
Correct |
12 ms |
320 KB |
Output is correct |
26 |
Correct |
24 ms |
312 KB |
Output is correct |
27 |
Correct |
19 ms |
208 KB |
Output is correct |
28 |
Correct |
7 ms |
208 KB |
Output is correct |
29 |
Correct |
31 ms |
316 KB |
Output is correct |
30 |
Correct |
21 ms |
208 KB |
Output is correct |
31 |
Correct |
15 ms |
300 KB |
Output is correct |
32 |
Correct |
20 ms |
312 KB |
Output is correct |
33 |
Correct |
26 ms |
312 KB |
Output is correct |
34 |
Correct |
14 ms |
312 KB |
Output is correct |
35 |
Correct |
23 ms |
312 KB |
Output is correct |
36 |
Correct |
22 ms |
320 KB |
Output is correct |
37 |
Correct |
19 ms |
320 KB |
Output is correct |
38 |
Correct |
31 ms |
208 KB |
Output is correct |
39 |
Correct |
29 ms |
328 KB |
Output is correct |
40 |
Correct |
11 ms |
320 KB |
Output is correct |
41 |
Correct |
7 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 |
1 ms |
240 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
0 ms |
304 KB |
Output is correct |
6 |
Correct |
0 ms |
208 KB |
Output is correct |
7 |
Correct |
37 ms |
316 KB |
Output is correct |
8 |
Correct |
21 ms |
328 KB |
Output is correct |
9 |
Correct |
38 ms |
304 KB |
Output is correct |
10 |
Correct |
32 ms |
312 KB |
Output is correct |
11 |
Partially correct |
55 ms |
308 KB |
Output is partially correct |
12 |
Correct |
25 ms |
324 KB |
Output is correct |
13 |
Partially correct |
53 ms |
308 KB |
Output is partially correct |
14 |
Correct |
49 ms |
208 KB |
Output is correct |
15 |
Correct |
29 ms |
320 KB |
Output is correct |
16 |
Correct |
39 ms |
316 KB |
Output is correct |
17 |
Correct |
44 ms |
308 KB |
Output is correct |
18 |
Correct |
48 ms |
316 KB |
Output is correct |
19 |
Correct |
31 ms |
320 KB |
Output is correct |
20 |
Correct |
47 ms |
316 KB |
Output is correct |
21 |
Partially correct |
47 ms |
332 KB |
Output is partially correct |
22 |
Correct |
46 ms |
320 KB |
Output is correct |
23 |
Correct |
42 ms |
308 KB |
Output is correct |
24 |
Correct |
24 ms |
320 KB |
Output is correct |
25 |
Correct |
25 ms |
316 KB |
Output is correct |
26 |
Correct |
13 ms |
336 KB |
Output is correct |
27 |
Correct |
35 ms |
304 KB |
Output is correct |
28 |
Correct |
44 ms |
304 KB |
Output is correct |
29 |
Correct |
29 ms |
308 KB |
Output is correct |
30 |
Correct |
27 ms |
332 KB |
Output is correct |
31 |
Correct |
38 ms |
300 KB |
Output is correct |
32 |
Correct |
39 ms |
312 KB |
Output is correct |
33 |
Partially correct |
55 ms |
300 KB |
Output is partially correct |
34 |
Partially correct |
62 ms |
316 KB |
Output is partially correct |
35 |
Correct |
36 ms |
312 KB |
Output is correct |
36 |
Correct |
33 ms |
320 KB |
Output is correct |
37 |
Correct |
49 ms |
300 KB |
Output is correct |
38 |
Correct |
32 ms |
320 KB |
Output is correct |
39 |
Correct |
34 ms |
448 KB |
Output is correct |
40 |
Correct |
31 ms |
328 KB |
Output is correct |
41 |
Correct |
34 ms |
320 KB |
Output is correct |
42 |
Correct |
41 ms |
300 KB |
Output is correct |
43 |
Correct |
11 ms |
208 KB |
Output is correct |
44 |
Correct |
27 ms |
308 KB |
Output is correct |
45 |
Correct |
29 ms |
300 KB |
Output is correct |
46 |
Correct |
26 ms |
312 KB |
Output is correct |
47 |
Correct |
25 ms |
208 KB |
Output is correct |
48 |
Correct |
28 ms |
332 KB |
Output is correct |