// Source: https://oj.uz/problem/view/IOI22_insects
//
#include "insects.h"
#include "bits/stdc++.h"
using namespace std;
#define s second
#define f first
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<int> vi;
#define FOR(i, a, b) for (int i = (a); i<b; i++)
bool ckmin(int& a, int b){ return b < a ? a = b, true : false; }
bool ckmax(int& a, int b){ return b > a ? a = b, true : false; }
set<int> in, out;
void gout(int i) {
in.erase(i);
out.insert(i);
move_outside(i);
}
void gin(int i) {
out.erase(i);
in.insert(i);
move_inside(i);
}
int min_cardinality(int n) {
// cout << n << endl;
FOR(i, 0, n) out.insert(i);
int d = n;
FOR(i, 0, n) {
gin(i);
if (press_button() > 1) {
gout(i);
d--;
}
}
set<int> oth = in;
for (auto val: oth) {
gout(val);
}
if (d == 1) {
return n;
}
int alr = 0;
// cout << 'd' << endl;
int prv = -1;
int lo = 1;
int hi = n / d;
// int alr = 0;
while (lo < hi) {
int t = (lo + hi + 1) / (2);
// cout << out.size() << t << endl;
// for (auto val: out) {
// cout << val << ' ';
// }
// cout << endl;
// testing t
// cout << lo << hi << t << endl;
set<int> oth = out;
for (auto val: oth) {
gin(val);
if (press_button() > t) {
gout(val);
}
}
// cout << in.size() << endl;
if (in.size() + alr == t * d) { // all here --- erase this section
// alr += t;
// for (auto it = in.begin(); it != in.end();) {
// move_outside(*it);
// it++;
// in.erase(prev(it, 1));
// }
// set<int> oth = in;
// for (auto val: oth) gout(val);
alr += in.size();
in.clear();
lo = t;
} else { // erase everything not in this section
out.clear();
set<int> oth = in;
for (auto val: oth) gout(val);
hi = t-1;
}
}
// cout << alr << endl;
return lo;
}
Compilation message
insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:86:25: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
86 | if (in.size() + alr == t * d) { // all here --- erase this section
| ~~~~~~~~~~~~~~~~^~~~~~~~
insects.cpp:65:7: warning: unused variable 'prv' [-Wunused-variable]
65 | int prv = -1;
| ^~~
# |
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 |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
440 KB |
Output is correct |
8 |
Correct |
3 ms |
344 KB |
Output is correct |
9 |
Correct |
3 ms |
344 KB |
Output is correct |
10 |
Correct |
2 ms |
600 KB |
Output is correct |
11 |
Correct |
2 ms |
600 KB |
Output is correct |
12 |
Correct |
3 ms |
600 KB |
Output is correct |
13 |
Correct |
3 ms |
600 KB |
Output is correct |
14 |
Correct |
3 ms |
600 KB |
Output is correct |
15 |
Correct |
3 ms |
344 KB |
Output is correct |
16 |
Correct |
3 ms |
600 KB |
Output is correct |
17 |
Correct |
2 ms |
344 KB |
Output is correct |
18 |
Correct |
3 ms |
600 KB |
Output is correct |
19 |
Correct |
2 ms |
600 KB |
Output is correct |
20 |
Correct |
3 ms |
856 KB |
Output is correct |
21 |
Correct |
2 ms |
456 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 |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
440 KB |
Output is correct |
8 |
Correct |
3 ms |
344 KB |
Output is correct |
9 |
Correct |
3 ms |
344 KB |
Output is correct |
10 |
Correct |
2 ms |
600 KB |
Output is correct |
11 |
Correct |
2 ms |
600 KB |
Output is correct |
12 |
Correct |
3 ms |
600 KB |
Output is correct |
13 |
Correct |
3 ms |
600 KB |
Output is correct |
14 |
Correct |
3 ms |
600 KB |
Output is correct |
15 |
Correct |
3 ms |
344 KB |
Output is correct |
16 |
Correct |
3 ms |
600 KB |
Output is correct |
17 |
Correct |
2 ms |
344 KB |
Output is correct |
18 |
Correct |
3 ms |
600 KB |
Output is correct |
19 |
Correct |
2 ms |
600 KB |
Output is correct |
20 |
Correct |
3 ms |
856 KB |
Output is correct |
21 |
Correct |
2 ms |
456 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
4 ms |
344 KB |
Output is correct |
24 |
Correct |
6 ms |
600 KB |
Output is correct |
25 |
Correct |
14 ms |
600 KB |
Output is correct |
26 |
Correct |
12 ms |
600 KB |
Output is correct |
27 |
Correct |
13 ms |
600 KB |
Output is correct |
28 |
Correct |
5 ms |
596 KB |
Output is correct |
29 |
Correct |
13 ms |
600 KB |
Output is correct |
30 |
Correct |
13 ms |
600 KB |
Output is correct |
31 |
Correct |
13 ms |
600 KB |
Output is correct |
32 |
Correct |
15 ms |
600 KB |
Output is correct |
33 |
Correct |
15 ms |
484 KB |
Output is correct |
34 |
Correct |
15 ms |
480 KB |
Output is correct |
35 |
Correct |
13 ms |
484 KB |
Output is correct |
36 |
Correct |
14 ms |
600 KB |
Output is correct |
37 |
Correct |
15 ms |
600 KB |
Output is correct |
38 |
Correct |
13 ms |
480 KB |
Output is correct |
39 |
Correct |
11 ms |
856 KB |
Output is correct |
40 |
Correct |
9 ms |
848 KB |
Output is correct |
41 |
Correct |
5 ms |
480 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 |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
10 ms |
344 KB |
Output is correct |
8 |
Correct |
11 ms |
500 KB |
Output is correct |
9 |
Correct |
30 ms |
520 KB |
Output is correct |
10 |
Correct |
29 ms |
600 KB |
Output is correct |
11 |
Correct |
25 ms |
516 KB |
Output is correct |
12 |
Correct |
20 ms |
736 KB |
Output is correct |
13 |
Correct |
27 ms |
596 KB |
Output is correct |
14 |
Correct |
41 ms |
604 KB |
Output is correct |
15 |
Correct |
28 ms |
600 KB |
Output is correct |
16 |
Correct |
29 ms |
504 KB |
Output is correct |
17 |
Correct |
29 ms |
520 KB |
Output is correct |
18 |
Correct |
32 ms |
528 KB |
Output is correct |
19 |
Partially correct |
30 ms |
708 KB |
Output is partially correct |
20 |
Correct |
33 ms |
772 KB |
Output is correct |
21 |
Correct |
36 ms |
600 KB |
Output is correct |
22 |
Partially correct |
30 ms |
596 KB |
Output is partially correct |
23 |
Correct |
31 ms |
868 KB |
Output is correct |
24 |
Correct |
24 ms |
504 KB |
Output is correct |
25 |
Correct |
19 ms |
852 KB |
Output is correct |
26 |
Correct |
11 ms |
600 KB |
Output is correct |
27 |
Correct |
34 ms |
524 KB |
Output is correct |
28 |
Correct |
29 ms |
516 KB |
Output is correct |
29 |
Partially correct |
32 ms |
504 KB |
Output is partially correct |
30 |
Partially correct |
28 ms |
600 KB |
Output is partially correct |
31 |
Correct |
29 ms |
616 KB |
Output is correct |
32 |
Correct |
27 ms |
692 KB |
Output is correct |
33 |
Correct |
31 ms |
500 KB |
Output is correct |
34 |
Correct |
27 ms |
1008 KB |
Output is correct |
35 |
Partially correct |
27 ms |
592 KB |
Output is partially correct |
36 |
Partially correct |
37 ms |
596 KB |
Output is partially correct |
37 |
Correct |
30 ms |
688 KB |
Output is correct |
38 |
Correct |
25 ms |
596 KB |
Output is correct |
39 |
Correct |
24 ms |
600 KB |
Output is correct |
40 |
Correct |
29 ms |
592 KB |
Output is correct |
41 |
Partially correct |
30 ms |
600 KB |
Output is partially correct |
42 |
Partially correct |
33 ms |
600 KB |
Output is partially correct |
43 |
Correct |
7 ms |
600 KB |
Output is correct |
44 |
Correct |
19 ms |
596 KB |
Output is correct |
45 |
Correct |
29 ms |
600 KB |
Output is correct |
46 |
Correct |
19 ms |
644 KB |
Output is correct |
47 |
Correct |
22 ms |
776 KB |
Output is correct |
48 |
Correct |
24 ms |
648 KB |
Output is correct |