#include "insects.h"
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
const ll INF = 1e9+7;
const ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ii,ll>
#define f(i,a,b) for(int i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Training
int min_cardinality(int N){
srand(time(0));
ll n = N;
set<ll>ex;
set<ll>olo;
bool v[n] = {0};
f(i,0,n){
move_inside(i);
olo.insert(i);
ex.insert(i);
v[i] = 1;
if(1 != press_button()){
ex.erase(i);
v[i] = 0;
move_outside(i);
}
}
ll d = ex.size();
ll l = 2,r = n / d;
ll ans = 1;
set<ll>cur = ex;
while(l <= r){
ll mid = (l+r)/2 + rand() % 2;
mid = min(mid,r);
for(auto x:olo){
if(!v[x]){
move_inside(x);
v[x] = 1;
cur.insert(x);
if(press_button() > mid){
move_outside(x);
cur.erase(x);
v[x] = 0;
}
}
}
if((ll)cur.size() == d * mid){
l = mid + 1;
ex = cur;
ans = max(ans,mid);
}
else{
olo = cur;
for(auto x:cur){
if(!ex.count(x)){
v[x] = 0;
move_outside(x);
}
}
cur = ex;
r = mid - 1;
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
4 ms |
208 KB |
Output is correct |
7 |
Correct |
2 ms |
304 KB |
Output is correct |
8 |
Correct |
4 ms |
208 KB |
Output is correct |
9 |
Correct |
4 ms |
316 KB |
Output is correct |
10 |
Correct |
3 ms |
300 KB |
Output is correct |
11 |
Correct |
2 ms |
208 KB |
Output is correct |
12 |
Correct |
4 ms |
208 KB |
Output is correct |
13 |
Correct |
3 ms |
208 KB |
Output is correct |
14 |
Correct |
5 ms |
308 KB |
Output is correct |
15 |
Correct |
3 ms |
208 KB |
Output is correct |
16 |
Correct |
5 ms |
208 KB |
Output is correct |
17 |
Correct |
4 ms |
300 KB |
Output is correct |
18 |
Correct |
4 ms |
208 KB |
Output is correct |
19 |
Correct |
2 ms |
208 KB |
Output is correct |
20 |
Correct |
3 ms |
208 KB |
Output is correct |
21 |
Correct |
2 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 |
4 ms |
208 KB |
Output is correct |
7 |
Correct |
2 ms |
304 KB |
Output is correct |
8 |
Correct |
4 ms |
208 KB |
Output is correct |
9 |
Correct |
4 ms |
316 KB |
Output is correct |
10 |
Correct |
3 ms |
300 KB |
Output is correct |
11 |
Correct |
2 ms |
208 KB |
Output is correct |
12 |
Correct |
4 ms |
208 KB |
Output is correct |
13 |
Correct |
3 ms |
208 KB |
Output is correct |
14 |
Correct |
5 ms |
308 KB |
Output is correct |
15 |
Correct |
3 ms |
208 KB |
Output is correct |
16 |
Correct |
5 ms |
208 KB |
Output is correct |
17 |
Correct |
4 ms |
300 KB |
Output is correct |
18 |
Correct |
4 ms |
208 KB |
Output is correct |
19 |
Correct |
2 ms |
208 KB |
Output is correct |
20 |
Correct |
3 ms |
208 KB |
Output is correct |
21 |
Correct |
2 ms |
208 KB |
Output is correct |
22 |
Correct |
2 ms |
208 KB |
Output is correct |
23 |
Correct |
21 ms |
384 KB |
Output is correct |
24 |
Correct |
9 ms |
428 KB |
Output is correct |
25 |
Correct |
25 ms |
412 KB |
Output is correct |
26 |
Correct |
25 ms |
328 KB |
Output is correct |
27 |
Correct |
19 ms |
328 KB |
Output is correct |
28 |
Correct |
8 ms |
336 KB |
Output is correct |
29 |
Correct |
15 ms |
336 KB |
Output is correct |
30 |
Correct |
20 ms |
324 KB |
Output is correct |
31 |
Correct |
24 ms |
312 KB |
Output is correct |
32 |
Correct |
24 ms |
348 KB |
Output is correct |
33 |
Correct |
15 ms |
332 KB |
Output is correct |
34 |
Correct |
23 ms |
352 KB |
Output is correct |
35 |
Correct |
21 ms |
332 KB |
Output is correct |
36 |
Correct |
24 ms |
352 KB |
Output is correct |
37 |
Correct |
26 ms |
356 KB |
Output is correct |
38 |
Correct |
16 ms |
320 KB |
Output is correct |
39 |
Correct |
19 ms |
336 KB |
Output is correct |
40 |
Correct |
9 ms |
328 KB |
Output is correct |
41 |
Correct |
8 ms |
320 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 |
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 |
45 ms |
496 KB |
Output is correct |
8 |
Correct |
12 ms |
508 KB |
Output is correct |
9 |
Correct |
34 ms |
608 KB |
Output is correct |
10 |
Correct |
44 ms |
476 KB |
Output is correct |
11 |
Correct |
35 ms |
348 KB |
Output is correct |
12 |
Correct |
20 ms |
452 KB |
Output is correct |
13 |
Correct |
46 ms |
460 KB |
Output is correct |
14 |
Correct |
32 ms |
376 KB |
Output is correct |
15 |
Correct |
36 ms |
576 KB |
Output is correct |
16 |
Correct |
53 ms |
516 KB |
Output is correct |
17 |
Correct |
42 ms |
484 KB |
Output is correct |
18 |
Correct |
49 ms |
524 KB |
Output is correct |
19 |
Correct |
26 ms |
464 KB |
Output is correct |
20 |
Correct |
37 ms |
584 KB |
Output is correct |
21 |
Correct |
23 ms |
480 KB |
Output is correct |
22 |
Correct |
46 ms |
336 KB |
Output is correct |
23 |
Correct |
45 ms |
344 KB |
Output is correct |
24 |
Correct |
26 ms |
556 KB |
Output is correct |
25 |
Correct |
18 ms |
468 KB |
Output is correct |
26 |
Correct |
10 ms |
444 KB |
Output is correct |
27 |
Correct |
47 ms |
468 KB |
Output is correct |
28 |
Correct |
21 ms |
420 KB |
Output is correct |
29 |
Correct |
52 ms |
528 KB |
Output is correct |
30 |
Correct |
28 ms |
608 KB |
Output is correct |
31 |
Correct |
52 ms |
456 KB |
Output is correct |
32 |
Correct |
52 ms |
484 KB |
Output is correct |
33 |
Correct |
60 ms |
412 KB |
Output is correct |
34 |
Correct |
32 ms |
580 KB |
Output is correct |
35 |
Correct |
49 ms |
420 KB |
Output is correct |
36 |
Correct |
37 ms |
520 KB |
Output is correct |
37 |
Correct |
37 ms |
456 KB |
Output is correct |
38 |
Correct |
50 ms |
496 KB |
Output is correct |
39 |
Correct |
35 ms |
500 KB |
Output is correct |
40 |
Correct |
26 ms |
544 KB |
Output is correct |
41 |
Correct |
39 ms |
464 KB |
Output is correct |
42 |
Correct |
23 ms |
460 KB |
Output is correct |
43 |
Correct |
9 ms |
304 KB |
Output is correct |
44 |
Correct |
36 ms |
360 KB |
Output is correct |
45 |
Correct |
50 ms |
680 KB |
Output is correct |
46 |
Correct |
19 ms |
424 KB |
Output is correct |
47 |
Correct |
21 ms |
380 KB |
Output is correct |
48 |
Correct |
19 ms |
384 KB |
Output is correct |