/*************************************
* author: marvinthang *
* created: 25.08.2022 22:19:29 *
*************************************/
#include <bits/stdc++.h>
#include "insects.h"
using namespace std;
#define fi first
#define se second
#define div ___div
#define left ___left
#define right ___right
#define TIME (1.0 * clock() / CLOCKS_PER_SEC)
#define MASK(i) (1LL << (i))
#define FULL(i) (MASK(i) - 1)
#define BIT(x, i) ((x) >> (i) & 1)
#define __builtin_popcount __builtin_popcountll
#define scan_op(...) istream & operator >> (istream &in, __VA_ARGS__ &u)
#define print_op(...) ostream & operator << (ostream &out, const __VA_ARGS__ &u)
#define file(name) if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }
template <class T> scan_op(vector <T>) { for (size_t i = 0; i < u.size(); ++i) in >> u[i]; return in; }
template <class T> print_op(vector <T>) { out << '{'; for (size_t i = 0; i + 1 < u.size(); ++i) out << u[i] << ", "; if (!u.empty()) out << u.back(); return out << '}'; }
template <class U, class V> scan_op(pair <U, V>) { return in >> u.fi >> u.se; }
template <class U, class V> print_op(pair <U, V>) { return out << '(' << u.fi << ", " << u.se << ')'; }
const double PI = 3.1415926535897932384626433832795; // acos(-1.0); atan(-1.0);
const int dir[] = {1, 0, -1, 0, 1, 1, -1, -1, 1}; // {2, 1, -2, -1, -2, 1, 2, -1, 2};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long rand(long long l, long long h) { return uniform_int_distribution <long long> (l, h) (rng); }
set <int> insides;
vector <int> order;
void add(int i) {
move_inside(order[i]);
insides.insert(i);
}
void remove(int i) {
move_outside(order[i]);
insides.erase(i);
}
void reset_machine(void) {
set <int> tmp = insides;
for (int i: tmp) remove(i);
}
int min_cardinality(int n) {
order.resize(n);
iota(order.begin(), order.end(), 0);
shuffle(order.begin(), order.end(), rng);
for (int i = 0; i < n; ++i) {
add(i);
if (press_button() > 1) remove(i);
}
map <int, set <int>> machine_states;
machine_states[1] = insides;
for (int i = 0; i < n; ++i) machine_states[n].insert(i);
int unique_vals = insides.size();
int l = 2, r = n / unique_vals;
while (l <= r) {
int m = l + r >> 1;
auto it = machine_states.lower_bound(m);
set <int> just_added;
for (int i: it->se) if (!insides.count(i)) {
add(i);
if (press_button() > m) remove(i);
else just_added.insert(i);
if (insides.size() >= unique_vals * m) break;
}
int total = insides.size();
machine_states[m] = insides;
if (total >= unique_vals * m) l = m + 1;
else {
r = m - 1;
for (int i: just_added) remove(i);
}
}
return r;
}
Compilation message
insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:68:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
68 | int m = l + r >> 1;
| ~~^~~
insects.cpp:75:23: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
75 | if (insides.size() >= unique_vals * m) break;
| ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
# |
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 |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
5 ms |
340 KB |
Output is correct |
7 |
Correct |
3 ms |
304 KB |
Output is correct |
8 |
Correct |
5 ms |
336 KB |
Output is correct |
9 |
Correct |
6 ms |
300 KB |
Output is correct |
10 |
Correct |
5 ms |
208 KB |
Output is correct |
11 |
Correct |
3 ms |
312 KB |
Output is correct |
12 |
Correct |
6 ms |
208 KB |
Output is correct |
13 |
Correct |
5 ms |
208 KB |
Output is correct |
14 |
Correct |
5 ms |
332 KB |
Output is correct |
15 |
Correct |
6 ms |
336 KB |
Output is correct |
16 |
Correct |
6 ms |
300 KB |
Output is correct |
17 |
Correct |
6 ms |
336 KB |
Output is correct |
18 |
Correct |
6 ms |
324 KB |
Output is correct |
19 |
Correct |
5 ms |
336 KB |
Output is correct |
20 |
Correct |
5 ms |
336 KB |
Output is correct |
21 |
Correct |
3 ms |
208 KB |
Output is correct |
22 |
Correct |
3 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 |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
5 ms |
340 KB |
Output is correct |
7 |
Correct |
3 ms |
304 KB |
Output is correct |
8 |
Correct |
5 ms |
336 KB |
Output is correct |
9 |
Correct |
6 ms |
300 KB |
Output is correct |
10 |
Correct |
5 ms |
208 KB |
Output is correct |
11 |
Correct |
3 ms |
312 KB |
Output is correct |
12 |
Correct |
6 ms |
208 KB |
Output is correct |
13 |
Correct |
5 ms |
208 KB |
Output is correct |
14 |
Correct |
5 ms |
332 KB |
Output is correct |
15 |
Correct |
6 ms |
336 KB |
Output is correct |
16 |
Correct |
6 ms |
300 KB |
Output is correct |
17 |
Correct |
6 ms |
336 KB |
Output is correct |
18 |
Correct |
6 ms |
324 KB |
Output is correct |
19 |
Correct |
5 ms |
336 KB |
Output is correct |
20 |
Correct |
5 ms |
336 KB |
Output is correct |
21 |
Correct |
3 ms |
208 KB |
Output is correct |
22 |
Correct |
3 ms |
208 KB |
Output is correct |
23 |
Correct |
22 ms |
680 KB |
Output is correct |
24 |
Correct |
12 ms |
328 KB |
Output is correct |
25 |
Correct |
23 ms |
540 KB |
Output is correct |
26 |
Correct |
22 ms |
408 KB |
Output is correct |
27 |
Correct |
22 ms |
328 KB |
Output is correct |
28 |
Correct |
9 ms |
312 KB |
Output is correct |
29 |
Correct |
26 ms |
376 KB |
Output is correct |
30 |
Correct |
36 ms |
380 KB |
Output is correct |
31 |
Correct |
21 ms |
628 KB |
Output is correct |
32 |
Correct |
25 ms |
552 KB |
Output is correct |
33 |
Correct |
22 ms |
532 KB |
Output is correct |
34 |
Correct |
22 ms |
556 KB |
Output is correct |
35 |
Correct |
22 ms |
544 KB |
Output is correct |
36 |
Correct |
18 ms |
584 KB |
Output is correct |
37 |
Correct |
22 ms |
548 KB |
Output is correct |
38 |
Correct |
23 ms |
328 KB |
Output is correct |
39 |
Correct |
19 ms |
384 KB |
Output is correct |
40 |
Correct |
16 ms |
328 KB |
Output is correct |
41 |
Correct |
9 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
40 ms |
1240 KB |
Output is correct |
8 |
Correct |
20 ms |
448 KB |
Output is correct |
9 |
Correct |
47 ms |
908 KB |
Output is correct |
10 |
Correct |
50 ms |
712 KB |
Output is correct |
11 |
Correct |
42 ms |
456 KB |
Output is correct |
12 |
Correct |
32 ms |
476 KB |
Output is correct |
13 |
Correct |
66 ms |
456 KB |
Output is correct |
14 |
Correct |
44 ms |
484 KB |
Output is correct |
15 |
Correct |
41 ms |
1100 KB |
Output is correct |
16 |
Correct |
45 ms |
1072 KB |
Output is correct |
17 |
Correct |
45 ms |
1072 KB |
Output is correct |
18 |
Correct |
37 ms |
852 KB |
Output is correct |
19 |
Correct |
42 ms |
1056 KB |
Output is correct |
20 |
Correct |
53 ms |
968 KB |
Output is correct |
21 |
Correct |
56 ms |
680 KB |
Output is correct |
22 |
Correct |
54 ms |
548 KB |
Output is correct |
23 |
Correct |
32 ms |
456 KB |
Output is correct |
24 |
Correct |
33 ms |
576 KB |
Output is correct |
25 |
Correct |
29 ms |
592 KB |
Output is correct |
26 |
Correct |
18 ms |
452 KB |
Output is correct |
27 |
Correct |
47 ms |
808 KB |
Output is correct |
28 |
Correct |
40 ms |
804 KB |
Output is correct |
29 |
Correct |
47 ms |
940 KB |
Output is correct |
30 |
Correct |
41 ms |
940 KB |
Output is correct |
31 |
Correct |
45 ms |
676 KB |
Output is correct |
32 |
Correct |
63 ms |
712 KB |
Output is correct |
33 |
Correct |
44 ms |
424 KB |
Output is correct |
34 |
Correct |
50 ms |
400 KB |
Output is correct |
35 |
Correct |
39 ms |
820 KB |
Output is correct |
36 |
Correct |
45 ms |
804 KB |
Output is correct |
37 |
Correct |
47 ms |
712 KB |
Output is correct |
38 |
Correct |
58 ms |
696 KB |
Output is correct |
39 |
Correct |
43 ms |
696 KB |
Output is correct |
40 |
Correct |
34 ms |
696 KB |
Output is correct |
41 |
Correct |
41 ms |
840 KB |
Output is correct |
42 |
Correct |
45 ms |
936 KB |
Output is correct |
43 |
Correct |
10 ms |
328 KB |
Output is correct |
44 |
Correct |
45 ms |
428 KB |
Output is correct |
45 |
Correct |
20 ms |
1312 KB |
Output is correct |
46 |
Correct |
32 ms |
424 KB |
Output is correct |
47 |
Correct |
20 ms |
436 KB |
Output is correct |
48 |
Correct |
25 ms |
460 KB |
Output is correct |