/**
* Author : Nguyen Tuan Vu
* Created : 03.01.2023
**/
#pragma GCC optimize("O2")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define MASK(x) ((1ll)<<(x))
#define BIT(x, i) (((x)>>(i))&(1))
#define ALL(v) (v).begin(), (v).end()
#define REP(i, n) for (int i = 0, _n = (n); i < _n; ++i)
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, b, a) for (int i = (b), _a = (a); i >= _a; --i)
template <class X, class Y> bool minimize(X &a, Y b) {
if (a > b) return a = b, true;
return false;
}
template <class X, class Y> bool maximize(X &a, Y b) {
if (a < b) return a = b, true;
return false;
}
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int Rand(int l, int r) {return l + rng() % (r - l + 1);}
const int N = 2023;
int n;
int d;
int c;
bool used[N];
bool skip[N];
void move_inside(int i);
void move_outside(int i);
int press_button();
void findDistinct() {
vector<int> p;
for (int i = 0; i < n; i++) {
move_inside(i);
if (press_button() == 1)
p.push_back(i);
else
move_outside(i);
}
for (int i : p) used[i] = true;
d = (int) p.size();
}
bool check(int x) {
c = 0;
for (int i = 0; i < n; i++)
c += used[i];
vector<int> ids;
for (int i = 0; i < n; i++)
if (!used[i] && !skip[i])
ids.push_back(i);
shuffle(ALL(ids), rng);
vector<int> p, q;
for (int i : ids) {
move_inside(i);
if (press_button() > x)
move_outside(i), q.push_back(i);
else
c++, p.push_back(i);
if (c == x * d)
break;
}
if (c == x * d) {
for (int i : p) used[i] = true;
return true;
} else {
for (int i : p) move_outside(i);
for (int i : q) skip[i] = true;
return false;
}
}
int min_cardinality(int N) {
n = N;
findDistinct();
if (d == 1)
return N;
// if (d == 2) {
// for (int i = 0; i < N; i++)
// if (!used[i])
// move_inside(i);
// return n - press_button();
// }
int l = 1, r = n / d + 1;
while(r - l > 1) {
int mid = (l + r) / 2;
if (check(mid))
l = mid;
else
r = mid, r = min(r, c / d + 1);
}
return l;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
308 KB |
Output is correct |
9 |
Correct |
4 ms |
304 KB |
Output is correct |
10 |
Correct |
4 ms |
272 KB |
Output is correct |
11 |
Correct |
3 ms |
208 KB |
Output is correct |
12 |
Correct |
4 ms |
304 KB |
Output is correct |
13 |
Correct |
5 ms |
208 KB |
Output is correct |
14 |
Correct |
5 ms |
208 KB |
Output is correct |
15 |
Correct |
5 ms |
304 KB |
Output is correct |
16 |
Correct |
4 ms |
208 KB |
Output is correct |
17 |
Correct |
5 ms |
208 KB |
Output is correct |
18 |
Correct |
7 ms |
208 KB |
Output is correct |
19 |
Correct |
4 ms |
208 KB |
Output is correct |
20 |
Correct |
4 ms |
208 KB |
Output is correct |
21 |
Correct |
5 ms |
208 KB |
Output is correct |
22 |
Correct |
2 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
308 KB |
Output is correct |
9 |
Correct |
4 ms |
304 KB |
Output is correct |
10 |
Correct |
4 ms |
272 KB |
Output is correct |
11 |
Correct |
3 ms |
208 KB |
Output is correct |
12 |
Correct |
4 ms |
304 KB |
Output is correct |
13 |
Correct |
5 ms |
208 KB |
Output is correct |
14 |
Correct |
5 ms |
208 KB |
Output is correct |
15 |
Correct |
5 ms |
304 KB |
Output is correct |
16 |
Correct |
4 ms |
208 KB |
Output is correct |
17 |
Correct |
5 ms |
208 KB |
Output is correct |
18 |
Correct |
7 ms |
208 KB |
Output is correct |
19 |
Correct |
4 ms |
208 KB |
Output is correct |
20 |
Correct |
4 ms |
208 KB |
Output is correct |
21 |
Correct |
5 ms |
208 KB |
Output is correct |
22 |
Correct |
2 ms |
208 KB |
Output is correct |
23 |
Correct |
10 ms |
208 KB |
Output is correct |
24 |
Correct |
8 ms |
316 KB |
Output is correct |
25 |
Correct |
19 ms |
208 KB |
Output is correct |
26 |
Correct |
26 ms |
308 KB |
Output is correct |
27 |
Correct |
19 ms |
284 KB |
Output is correct |
28 |
Correct |
9 ms |
208 KB |
Output is correct |
29 |
Correct |
20 ms |
304 KB |
Output is correct |
30 |
Correct |
22 ms |
292 KB |
Output is correct |
31 |
Correct |
18 ms |
260 KB |
Output is correct |
32 |
Correct |
16 ms |
208 KB |
Output is correct |
33 |
Correct |
27 ms |
208 KB |
Output is correct |
34 |
Correct |
18 ms |
208 KB |
Output is correct |
35 |
Correct |
18 ms |
208 KB |
Output is correct |
36 |
Correct |
17 ms |
304 KB |
Output is correct |
37 |
Correct |
31 ms |
208 KB |
Output is correct |
38 |
Correct |
20 ms |
208 KB |
Output is correct |
39 |
Correct |
20 ms |
208 KB |
Output is correct |
40 |
Correct |
18 ms |
208 KB |
Output is correct |
41 |
Correct |
9 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
15 ms |
208 KB |
Output is correct |
8 |
Correct |
19 ms |
308 KB |
Output is correct |
9 |
Correct |
42 ms |
288 KB |
Output is correct |
10 |
Correct |
45 ms |
304 KB |
Output is correct |
11 |
Correct |
49 ms |
300 KB |
Output is correct |
12 |
Correct |
28 ms |
296 KB |
Output is correct |
13 |
Correct |
47 ms |
288 KB |
Output is correct |
14 |
Correct |
56 ms |
308 KB |
Output is correct |
15 |
Correct |
36 ms |
208 KB |
Output is correct |
16 |
Correct |
37 ms |
288 KB |
Output is correct |
17 |
Correct |
42 ms |
292 KB |
Output is correct |
18 |
Correct |
42 ms |
284 KB |
Output is correct |
19 |
Correct |
39 ms |
308 KB |
Output is correct |
20 |
Correct |
37 ms |
296 KB |
Output is correct |
21 |
Correct |
56 ms |
208 KB |
Output is correct |
22 |
Correct |
46 ms |
288 KB |
Output is correct |
23 |
Correct |
34 ms |
292 KB |
Output is correct |
24 |
Correct |
33 ms |
208 KB |
Output is correct |
25 |
Correct |
31 ms |
316 KB |
Output is correct |
26 |
Correct |
19 ms |
312 KB |
Output is correct |
27 |
Correct |
21 ms |
296 KB |
Output is correct |
28 |
Correct |
45 ms |
284 KB |
Output is correct |
29 |
Correct |
46 ms |
296 KB |
Output is correct |
30 |
Correct |
49 ms |
296 KB |
Output is correct |
31 |
Correct |
49 ms |
304 KB |
Output is correct |
32 |
Correct |
49 ms |
292 KB |
Output is correct |
33 |
Correct |
45 ms |
300 KB |
Output is correct |
34 |
Correct |
46 ms |
300 KB |
Output is correct |
35 |
Correct |
36 ms |
300 KB |
Output is correct |
36 |
Correct |
35 ms |
208 KB |
Output is correct |
37 |
Correct |
45 ms |
300 KB |
Output is correct |
38 |
Correct |
52 ms |
304 KB |
Output is correct |
39 |
Correct |
37 ms |
300 KB |
Output is correct |
40 |
Correct |
41 ms |
416 KB |
Output is correct |
41 |
Correct |
38 ms |
292 KB |
Output is correct |
42 |
Correct |
41 ms |
284 KB |
Output is correct |
43 |
Correct |
10 ms |
308 KB |
Output is correct |
44 |
Correct |
28 ms |
208 KB |
Output is correct |
45 |
Correct |
36 ms |
284 KB |
Output is correct |
46 |
Correct |
27 ms |
300 KB |
Output is correct |
47 |
Correct |
23 ms |
308 KB |
Output is correct |
48 |
Correct |
28 ms |
208 KB |
Output is correct |