#include "insects.h"
#include <iostream>
#include <vector>
#include <random>
#define ll long long
using namespace std;
random_device rd;
mt19937 mt(rd());
int min_cardinality(int N) {
vector <ll> V, X, A, B;
ll s = 0, a, b, mid, f = 1;
for (int i=0; i<N; ++i) {
move_inside(i);
auto res = press_button();
if (res > 1) {
move_outside(i);
X.push_back(i);
}
else V.push_back(i);
}
for (auto u : V) move_outside(u);
s = V.size();
while (true) {
A.clear();
B.clear();
if (X.size() < s) return f;
a = (X.size() / s) / 2;
a = max(a, 1LL);
b = a+1;
b = min(b, (ll)X.size()/s);
if (abs(a*s-(ll)X.size()/2) > abs(b*s-(ll)X.size()/2) || mt() % 4 == 3) mid = b;
else mid = a;
ll p = -1;
for (auto u : X) {
move_inside(u);
auto res = press_button();
if (res == mid && p == -1) p = u;
if (res > mid) {
B.push_back(u);
move_outside(u);
}
else A.push_back(u);
}
for (auto u : A) move_outside(u);
if (A.size() == mid * s) {
swap(X, B);
f += mid;
}
else {
swap(X, A);
for (int i=0; i<X.size(); ++i) {
if (X[i] == p) {
swap(X[i], X.back());
X.pop_back();
break;
}
}
}
}
}
Compilation message
insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:28:18: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
28 | if (X.size() < s) return f;
| ~~~~~~~~~^~~
insects.cpp:47:18: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
47 | if (A.size() == mid * s) {
| ~~~~~~~~~^~~~~~~~~~
insects.cpp:53:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for (int i=0; i<X.size(); ++i) {
| ~^~~~~~~~~
# |
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 |
Correct |
5 ms |
344 KB |
Output is correct |
7 |
Correct |
2 ms |
344 KB |
Output is correct |
8 |
Correct |
4 ms |
344 KB |
Output is correct |
9 |
Correct |
3 ms |
344 KB |
Output is correct |
10 |
Correct |
3 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
4 ms |
344 KB |
Output is correct |
13 |
Correct |
3 ms |
344 KB |
Output is correct |
14 |
Correct |
3 ms |
344 KB |
Output is correct |
15 |
Correct |
2 ms |
344 KB |
Output is correct |
16 |
Correct |
4 ms |
344 KB |
Output is correct |
17 |
Correct |
4 ms |
344 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
3 ms |
344 KB |
Output is correct |
20 |
Correct |
3 ms |
344 KB |
Output is correct |
21 |
Correct |
2 ms |
600 KB |
Output is correct |
22 |
Correct |
1 ms |
344 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 |
Correct |
5 ms |
344 KB |
Output is correct |
7 |
Correct |
2 ms |
344 KB |
Output is correct |
8 |
Correct |
4 ms |
344 KB |
Output is correct |
9 |
Correct |
3 ms |
344 KB |
Output is correct |
10 |
Correct |
3 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
4 ms |
344 KB |
Output is correct |
13 |
Correct |
3 ms |
344 KB |
Output is correct |
14 |
Correct |
3 ms |
344 KB |
Output is correct |
15 |
Correct |
2 ms |
344 KB |
Output is correct |
16 |
Correct |
4 ms |
344 KB |
Output is correct |
17 |
Correct |
4 ms |
344 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
3 ms |
344 KB |
Output is correct |
20 |
Correct |
3 ms |
344 KB |
Output is correct |
21 |
Correct |
2 ms |
600 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
10 ms |
596 KB |
Output is correct |
24 |
Correct |
5 ms |
344 KB |
Output is correct |
25 |
Correct |
18 ms |
444 KB |
Output is correct |
26 |
Correct |
20 ms |
344 KB |
Output is correct |
27 |
Correct |
12 ms |
344 KB |
Output is correct |
28 |
Correct |
6 ms |
344 KB |
Output is correct |
29 |
Correct |
12 ms |
464 KB |
Output is correct |
30 |
Correct |
20 ms |
856 KB |
Output is correct |
31 |
Correct |
20 ms |
456 KB |
Output is correct |
32 |
Correct |
19 ms |
464 KB |
Output is correct |
33 |
Correct |
12 ms |
460 KB |
Output is correct |
34 |
Correct |
11 ms |
344 KB |
Output is correct |
35 |
Correct |
22 ms |
600 KB |
Output is correct |
36 |
Correct |
18 ms |
344 KB |
Output is correct |
37 |
Correct |
17 ms |
344 KB |
Output is correct |
38 |
Correct |
10 ms |
600 KB |
Output is correct |
39 |
Correct |
10 ms |
720 KB |
Output is correct |
40 |
Correct |
9 ms |
600 KB |
Output is correct |
41 |
Correct |
3 ms |
460 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 |
1 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 |
26 ms |
724 KB |
Output is correct |
8 |
Correct |
10 ms |
344 KB |
Output is correct |
9 |
Correct |
28 ms |
460 KB |
Output is correct |
10 |
Correct |
29 ms |
344 KB |
Output is correct |
11 |
Correct |
29 ms |
708 KB |
Output is correct |
12 |
Correct |
14 ms |
344 KB |
Output is correct |
13 |
Correct |
25 ms |
484 KB |
Output is correct |
14 |
Correct |
29 ms |
344 KB |
Output is correct |
15 |
Correct |
32 ms |
720 KB |
Output is correct |
16 |
Correct |
33 ms |
708 KB |
Output is correct |
17 |
Correct |
29 ms |
600 KB |
Output is correct |
18 |
Correct |
38 ms |
592 KB |
Output is correct |
19 |
Correct |
38 ms |
696 KB |
Output is correct |
20 |
Correct |
37 ms |
600 KB |
Output is correct |
21 |
Correct |
23 ms |
468 KB |
Output is correct |
22 |
Correct |
35 ms |
712 KB |
Output is correct |
23 |
Correct |
35 ms |
464 KB |
Output is correct |
24 |
Correct |
20 ms |
856 KB |
Output is correct |
25 |
Correct |
14 ms |
680 KB |
Output is correct |
26 |
Correct |
7 ms |
344 KB |
Output is correct |
27 |
Correct |
36 ms |
600 KB |
Output is correct |
28 |
Correct |
34 ms |
600 KB |
Output is correct |
29 |
Correct |
38 ms |
612 KB |
Output is correct |
30 |
Correct |
28 ms |
344 KB |
Output is correct |
31 |
Correct |
21 ms |
344 KB |
Output is correct |
32 |
Correct |
37 ms |
344 KB |
Output is correct |
33 |
Correct |
29 ms |
712 KB |
Output is correct |
34 |
Correct |
24 ms |
344 KB |
Output is correct |
35 |
Correct |
33 ms |
696 KB |
Output is correct |
36 |
Partially correct |
28 ms |
600 KB |
Output is partially correct |
37 |
Correct |
29 ms |
592 KB |
Output is correct |
38 |
Correct |
34 ms |
344 KB |
Output is correct |
39 |
Correct |
34 ms |
600 KB |
Output is correct |
40 |
Correct |
32 ms |
940 KB |
Output is correct |
41 |
Correct |
25 ms |
344 KB |
Output is correct |
42 |
Partially correct |
26 ms |
464 KB |
Output is partially correct |
43 |
Correct |
10 ms |
468 KB |
Output is correct |
44 |
Correct |
26 ms |
600 KB |
Output is correct |
45 |
Correct |
47 ms |
600 KB |
Output is correct |
46 |
Correct |
23 ms |
688 KB |
Output is correct |
47 |
Correct |
22 ms |
592 KB |
Output is correct |
48 |
Correct |
19 ms |
452 KB |
Output is correct |