#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 |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
332 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 |
208 KB |
Output is correct |
8 |
Correct |
4 ms |
208 KB |
Output is correct |
9 |
Correct |
5 ms |
208 KB |
Output is correct |
10 |
Correct |
5 ms |
208 KB |
Output is correct |
11 |
Correct |
2 ms |
208 KB |
Output is correct |
12 |
Correct |
6 ms |
208 KB |
Output is correct |
13 |
Correct |
6 ms |
208 KB |
Output is correct |
14 |
Correct |
5 ms |
336 KB |
Output is correct |
15 |
Correct |
4 ms |
336 KB |
Output is correct |
16 |
Correct |
5 ms |
208 KB |
Output is correct |
17 |
Correct |
5 ms |
304 KB |
Output is correct |
18 |
Correct |
4 ms |
208 KB |
Output is correct |
19 |
Correct |
3 ms |
208 KB |
Output is correct |
20 |
Correct |
4 ms |
208 KB |
Output is correct |
21 |
Correct |
3 ms |
208 KB |
Output is correct |
22 |
Correct |
2 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
332 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 |
208 KB |
Output is correct |
8 |
Correct |
4 ms |
208 KB |
Output is correct |
9 |
Correct |
5 ms |
208 KB |
Output is correct |
10 |
Correct |
5 ms |
208 KB |
Output is correct |
11 |
Correct |
2 ms |
208 KB |
Output is correct |
12 |
Correct |
6 ms |
208 KB |
Output is correct |
13 |
Correct |
6 ms |
208 KB |
Output is correct |
14 |
Correct |
5 ms |
336 KB |
Output is correct |
15 |
Correct |
4 ms |
336 KB |
Output is correct |
16 |
Correct |
5 ms |
208 KB |
Output is correct |
17 |
Correct |
5 ms |
304 KB |
Output is correct |
18 |
Correct |
4 ms |
208 KB |
Output is correct |
19 |
Correct |
3 ms |
208 KB |
Output is correct |
20 |
Correct |
4 ms |
208 KB |
Output is correct |
21 |
Correct |
3 ms |
208 KB |
Output is correct |
22 |
Correct |
2 ms |
208 KB |
Output is correct |
23 |
Correct |
25 ms |
336 KB |
Output is correct |
24 |
Correct |
9 ms |
368 KB |
Output is correct |
25 |
Correct |
19 ms |
404 KB |
Output is correct |
26 |
Correct |
25 ms |
336 KB |
Output is correct |
27 |
Correct |
16 ms |
336 KB |
Output is correct |
28 |
Correct |
9 ms |
324 KB |
Output is correct |
29 |
Correct |
17 ms |
336 KB |
Output is correct |
30 |
Correct |
21 ms |
344 KB |
Output is correct |
31 |
Correct |
25 ms |
352 KB |
Output is correct |
32 |
Correct |
28 ms |
356 KB |
Output is correct |
33 |
Correct |
27 ms |
324 KB |
Output is correct |
34 |
Correct |
26 ms |
328 KB |
Output is correct |
35 |
Correct |
28 ms |
404 KB |
Output is correct |
36 |
Correct |
16 ms |
336 KB |
Output is correct |
37 |
Correct |
22 ms |
456 KB |
Output is correct |
38 |
Correct |
23 ms |
356 KB |
Output is correct |
39 |
Correct |
22 ms |
332 KB |
Output is correct |
40 |
Correct |
11 ms |
348 KB |
Output is correct |
41 |
Correct |
6 ms |
584 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 |
0 ms |
208 KB |
Output is correct |
7 |
Correct |
40 ms |
524 KB |
Output is correct |
8 |
Correct |
18 ms |
500 KB |
Output is correct |
9 |
Correct |
36 ms |
568 KB |
Output is correct |
10 |
Correct |
26 ms |
588 KB |
Output is correct |
11 |
Correct |
42 ms |
428 KB |
Output is correct |
12 |
Correct |
25 ms |
460 KB |
Output is correct |
13 |
Correct |
31 ms |
336 KB |
Output is correct |
14 |
Correct |
30 ms |
416 KB |
Output is correct |
15 |
Correct |
52 ms |
524 KB |
Output is correct |
16 |
Correct |
53 ms |
460 KB |
Output is correct |
17 |
Correct |
33 ms |
420 KB |
Output is correct |
18 |
Correct |
39 ms |
524 KB |
Output is correct |
19 |
Correct |
37 ms |
468 KB |
Output is correct |
20 |
Correct |
45 ms |
508 KB |
Output is correct |
21 |
Correct |
43 ms |
428 KB |
Output is correct |
22 |
Correct |
47 ms |
408 KB |
Output is correct |
23 |
Correct |
29 ms |
460 KB |
Output is correct |
24 |
Correct |
41 ms |
456 KB |
Output is correct |
25 |
Correct |
24 ms |
404 KB |
Output is correct |
26 |
Correct |
17 ms |
428 KB |
Output is correct |
27 |
Correct |
56 ms |
420 KB |
Output is correct |
28 |
Correct |
27 ms |
424 KB |
Output is correct |
29 |
Correct |
37 ms |
576 KB |
Output is correct |
30 |
Correct |
40 ms |
548 KB |
Output is correct |
31 |
Partially correct |
54 ms |
400 KB |
Output is partially correct |
32 |
Partially correct |
50 ms |
456 KB |
Output is partially correct |
33 |
Correct |
50 ms |
336 KB |
Output is correct |
34 |
Correct |
52 ms |
408 KB |
Output is correct |
35 |
Correct |
51 ms |
456 KB |
Output is correct |
36 |
Correct |
39 ms |
420 KB |
Output is correct |
37 |
Correct |
34 ms |
544 KB |
Output is correct |
38 |
Correct |
41 ms |
464 KB |
Output is correct |
39 |
Correct |
32 ms |
496 KB |
Output is correct |
40 |
Correct |
49 ms |
456 KB |
Output is correct |
41 |
Correct |
35 ms |
492 KB |
Output is correct |
42 |
Correct |
46 ms |
580 KB |
Output is correct |
43 |
Correct |
9 ms |
208 KB |
Output is correct |
44 |
Correct |
30 ms |
336 KB |
Output is correct |
45 |
Correct |
25 ms |
556 KB |
Output is correct |
46 |
Correct |
22 ms |
372 KB |
Output is correct |
47 |
Correct |
27 ms |
460 KB |
Output is correct |
48 |
Correct |
27 ms |
456 KB |
Output is correct |