#include "bits/extc++.h"
using namespace std;
template <typename T>
void dbgh(const T& t) {
cerr << t << endl;
}
template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
cerr << t << " | ";
dbgh(u...);
}
#ifdef DEBUG
#define dbg(...) \
cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]" \
<< ": "; \
dbgh(__VA_ARGS__)
#else
#define cerr \
if (false) \
cerr
#define dbg(...)
#endif
#define endl "\n"
#define long int64_t
#define sz(x) int(size(x))
void move_inside(int i);
void move_outside(int i);
int press_button();
int min_cardinality(int n) {
mt19937 cowng(chrono::steady_clock::now().time_since_epoch().count());
int perm[n];
iota(perm, perm + n, 0);
shuffle(perm, perm + n, cowng);
set<int> s;
auto move_in = [&](int i) -> void {
move_inside(perm[i]);
assert(!s.count(i));
s.insert(i);
};
auto move_out = [&](int i) -> void {
move_outside(perm[i]);
assert(s.count(i));
s.erase(i);
};
auto press_but = [&]() -> int {
assert(sz(s));
return press_button();
};
for (int i = 0; i < n; i++) {
move_in(i);
if (press_but() > 1) {
move_out(i);
}
}
int distinct_cnt = sz(s);
int l = 1, r = n / distinct_cnt;
set<int> pool;
for (int i = 0; i < n; i++) {
pool.insert(i);
}
while (l < r) {
assert(sz(s) == distinct_cnt * l);
const int p = 48;
int mid = max(l + 1, (p * l + (100 - p) * r) / 100);
vector<int> outside, changed;
for (auto& a : pool) {
if (!s.count(a)) {
outside.push_back(a);
}
}
for (int i = 0; i < sz(outside) && sz(s) != distinct_cnt * mid; i++) {
int x = outside[i];
move_in(x);
if (press_but() > mid) {
move_out(x);
} else {
changed.push_back(x);
}
}
if (sz(s) == distinct_cnt * mid) {
l = mid;
} else {
r = mid - 1;
pool = s;
for (auto& a : changed) {
move_out(a);
}
}
}
return l;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 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 |
2 ms |
208 KB |
Output is correct |
7 |
Correct |
2 ms |
300 KB |
Output is correct |
8 |
Correct |
5 ms |
208 KB |
Output is correct |
9 |
Correct |
4 ms |
208 KB |
Output is correct |
10 |
Correct |
5 ms |
304 KB |
Output is correct |
11 |
Correct |
3 ms |
304 KB |
Output is correct |
12 |
Correct |
7 ms |
304 KB |
Output is correct |
13 |
Correct |
6 ms |
304 KB |
Output is correct |
14 |
Correct |
4 ms |
208 KB |
Output is correct |
15 |
Correct |
6 ms |
312 KB |
Output is correct |
16 |
Correct |
4 ms |
208 KB |
Output is correct |
17 |
Correct |
6 ms |
208 KB |
Output is correct |
18 |
Correct |
6 ms |
304 KB |
Output is correct |
19 |
Correct |
5 ms |
208 KB |
Output is correct |
20 |
Correct |
4 ms |
300 KB |
Output is correct |
21 |
Correct |
3 ms |
336 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 |
1 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 |
2 ms |
208 KB |
Output is correct |
7 |
Correct |
2 ms |
300 KB |
Output is correct |
8 |
Correct |
5 ms |
208 KB |
Output is correct |
9 |
Correct |
4 ms |
208 KB |
Output is correct |
10 |
Correct |
5 ms |
304 KB |
Output is correct |
11 |
Correct |
3 ms |
304 KB |
Output is correct |
12 |
Correct |
7 ms |
304 KB |
Output is correct |
13 |
Correct |
6 ms |
304 KB |
Output is correct |
14 |
Correct |
4 ms |
208 KB |
Output is correct |
15 |
Correct |
6 ms |
312 KB |
Output is correct |
16 |
Correct |
4 ms |
208 KB |
Output is correct |
17 |
Correct |
6 ms |
208 KB |
Output is correct |
18 |
Correct |
6 ms |
304 KB |
Output is correct |
19 |
Correct |
5 ms |
208 KB |
Output is correct |
20 |
Correct |
4 ms |
300 KB |
Output is correct |
21 |
Correct |
3 ms |
336 KB |
Output is correct |
22 |
Correct |
2 ms |
208 KB |
Output is correct |
23 |
Correct |
21 ms |
356 KB |
Output is correct |
24 |
Correct |
10 ms |
336 KB |
Output is correct |
25 |
Correct |
22 ms |
300 KB |
Output is correct |
26 |
Correct |
29 ms |
344 KB |
Output is correct |
27 |
Correct |
28 ms |
300 KB |
Output is correct |
28 |
Correct |
10 ms |
300 KB |
Output is correct |
29 |
Correct |
29 ms |
392 KB |
Output is correct |
30 |
Correct |
29 ms |
348 KB |
Output is correct |
31 |
Correct |
28 ms |
368 KB |
Output is correct |
32 |
Correct |
27 ms |
332 KB |
Output is correct |
33 |
Correct |
19 ms |
424 KB |
Output is correct |
34 |
Correct |
27 ms |
288 KB |
Output is correct |
35 |
Correct |
24 ms |
372 KB |
Output is correct |
36 |
Correct |
27 ms |
300 KB |
Output is correct |
37 |
Correct |
28 ms |
304 KB |
Output is correct |
38 |
Correct |
25 ms |
300 KB |
Output is correct |
39 |
Correct |
26 ms |
308 KB |
Output is correct |
40 |
Correct |
14 ms |
368 KB |
Output is correct |
41 |
Correct |
8 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 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 |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
31 ms |
440 KB |
Output is correct |
8 |
Correct |
16 ms |
376 KB |
Output is correct |
9 |
Correct |
22 ms |
456 KB |
Output is correct |
10 |
Correct |
57 ms |
424 KB |
Output is correct |
11 |
Correct |
42 ms |
412 KB |
Output is correct |
12 |
Correct |
23 ms |
436 KB |
Output is correct |
13 |
Correct |
59 ms |
424 KB |
Output is correct |
14 |
Correct |
49 ms |
552 KB |
Output is correct |
15 |
Correct |
32 ms |
456 KB |
Output is correct |
16 |
Correct |
46 ms |
428 KB |
Output is correct |
17 |
Correct |
23 ms |
432 KB |
Output is correct |
18 |
Correct |
56 ms |
468 KB |
Output is correct |
19 |
Correct |
50 ms |
452 KB |
Output is correct |
20 |
Correct |
37 ms |
456 KB |
Output is correct |
21 |
Correct |
43 ms |
460 KB |
Output is correct |
22 |
Correct |
60 ms |
448 KB |
Output is correct |
23 |
Correct |
38 ms |
332 KB |
Output is correct |
24 |
Correct |
36 ms |
316 KB |
Output is correct |
25 |
Correct |
19 ms |
448 KB |
Output is correct |
26 |
Correct |
18 ms |
332 KB |
Output is correct |
27 |
Correct |
53 ms |
572 KB |
Output is correct |
28 |
Correct |
57 ms |
420 KB |
Output is correct |
29 |
Correct |
47 ms |
424 KB |
Output is correct |
30 |
Correct |
49 ms |
456 KB |
Output is correct |
31 |
Correct |
46 ms |
424 KB |
Output is correct |
32 |
Correct |
29 ms |
480 KB |
Output is correct |
33 |
Correct |
45 ms |
424 KB |
Output is correct |
34 |
Correct |
56 ms |
436 KB |
Output is correct |
35 |
Correct |
58 ms |
444 KB |
Output is correct |
36 |
Correct |
53 ms |
420 KB |
Output is correct |
37 |
Correct |
60 ms |
452 KB |
Output is correct |
38 |
Correct |
63 ms |
448 KB |
Output is correct |
39 |
Correct |
57 ms |
420 KB |
Output is correct |
40 |
Correct |
58 ms |
468 KB |
Output is correct |
41 |
Correct |
51 ms |
496 KB |
Output is correct |
42 |
Correct |
45 ms |
452 KB |
Output is correct |
43 |
Correct |
11 ms |
304 KB |
Output is correct |
44 |
Correct |
54 ms |
288 KB |
Output is correct |
45 |
Correct |
39 ms |
416 KB |
Output is correct |
46 |
Correct |
30 ms |
312 KB |
Output is correct |
47 |
Correct |
29 ms |
436 KB |
Output is correct |
48 |
Correct |
30 ms |
320 KB |
Output is correct |