#include "insects.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> perm;
void mi(int i){
move_inside(perm[i]);
}
void mo(int i){
move_outside(perm[i]);
}
int min_cardinality(int N) {
default_random_engine dre(time(NULL));
perm.resize(N);
iota(perm.begin(), perm.end(), 0);
shuffle(perm.begin(), perm.end(), dre);
set<int> specials;
specials.insert(0);
mi(0);
for(int i = 1; i < N; i++){
mi(i);
if(press_button() == 2){
mo(i);
}else{
specials.insert(i);
}
}
for(int i : specials) mo(i);
// 2 cases: #t <= sqrt(N) or #t > sqrt(N)
if(specials.size() * specials.size() <= 1.5 * N){
// case 1: use N log2 #t approach using pbsearch
vector<tuple<int,int,int>> pbs;
int c = -1;
for(int i = 0; i < N; i++){
if(specials.count(i) == 0) pbs.push_back({i, 0, c});
else c++;
}
vector<int> svec(specials.begin(), specials.end());
int ptr = -1;
while(true){
bool cont = false;
for(auto p : pbs){
if(get<1>(p) != get<2>(p)) cont = true;
}
if(!cont) break;
sort(pbs.begin(), pbs.end(), [](tuple<int,int,int> x, tuple<int,int,int> y){
return (get<1>(x) + get<2>(x)) / 2 < (get<1>(y) + get<2>(y)) / 2;
});
while(ptr > (get<1>(pbs.front()) + get<2>(pbs.front())) / 2){
mo(svec[ptr]);
ptr--;
}
vector<tuple<int,int,int>> npbs;
for(auto p : pbs){
if(get<1>(p) == get<2>(p)){
npbs.push_back(p);
continue;
}
int mid = (get<1>(p) + get<2>(p)) / 2;
for(int i = ptr+1; i <= mid; i++) mi(svec[i]);
ptr = mid;
mi(get<0>(p));
if(press_button() == 2){
// hi = mid
npbs.push_back({get<0>(p), get<1>(p), mid});
}else{
// lo = mid+1
npbs.push_back({get<0>(p), mid+1, get<2>(p)});
}
mo(get<0>(p));
}
pbs = npbs;
}
map<int,int> cards;
for(int x : specials) cards[x] = 1;
for(auto p : pbs) cards[svec[get<1>(p)]]++;
int mn = 5000;
for(auto x : cards) mn = min(mn, x.second);
return mn;
}else{
// case 2: use N log2 ans approach using bsearch on ans
int lo = 1;
int hi = N / specials.size();
int mid;
while(lo < hi){
mid = (lo + hi)/2;
set<int> machine;
for(int i = 0; i < N; i++){
if(specials.count(i) == 0){
mi(i);
machine.insert(i);
if(press_button() > mid){
machine.erase(i);
mo(i);
}
}
}
bool ok = false;
vector<int> svec(specials.begin(), specials.end());
shuffle(svec.begin(), svec.end(), dre);
for(int x : svec){
mi(x);
machine.insert(x);
if(press_button() == mid){
ok = true;
break;
}
mo(x);
machine.erase(x);
}
for(int x : machine){
mo(x);
}
if(ok){
hi = mid;
}else{
lo = mid+1;
}
}
return lo;
}
}
# |
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 |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 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 |
7 ms |
208 KB |
Output is correct |
9 |
Correct |
7 ms |
304 KB |
Output is correct |
10 |
Correct |
3 ms |
312 KB |
Output is correct |
11 |
Correct |
2 ms |
208 KB |
Output is correct |
12 |
Correct |
3 ms |
208 KB |
Output is correct |
13 |
Correct |
13 ms |
208 KB |
Output is correct |
14 |
Correct |
6 ms |
256 KB |
Output is correct |
15 |
Correct |
5 ms |
304 KB |
Output is correct |
16 |
Correct |
7 ms |
208 KB |
Output is correct |
17 |
Correct |
7 ms |
208 KB |
Output is correct |
18 |
Correct |
7 ms |
304 KB |
Output is correct |
19 |
Correct |
5 ms |
208 KB |
Output is correct |
20 |
Correct |
5 ms |
208 KB |
Output is correct |
21 |
Correct |
3 ms |
308 KB |
Output is correct |
22 |
Correct |
1 ms |
212 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 |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 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 |
7 ms |
208 KB |
Output is correct |
9 |
Correct |
7 ms |
304 KB |
Output is correct |
10 |
Correct |
3 ms |
312 KB |
Output is correct |
11 |
Correct |
2 ms |
208 KB |
Output is correct |
12 |
Correct |
3 ms |
208 KB |
Output is correct |
13 |
Correct |
13 ms |
208 KB |
Output is correct |
14 |
Correct |
6 ms |
256 KB |
Output is correct |
15 |
Correct |
5 ms |
304 KB |
Output is correct |
16 |
Correct |
7 ms |
208 KB |
Output is correct |
17 |
Correct |
7 ms |
208 KB |
Output is correct |
18 |
Correct |
7 ms |
304 KB |
Output is correct |
19 |
Correct |
5 ms |
208 KB |
Output is correct |
20 |
Correct |
5 ms |
208 KB |
Output is correct |
21 |
Correct |
3 ms |
308 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
10 ms |
292 KB |
Output is correct |
24 |
Correct |
8 ms |
340 KB |
Output is correct |
25 |
Correct |
46 ms |
296 KB |
Output is correct |
26 |
Correct |
49 ms |
328 KB |
Output is correct |
27 |
Correct |
5 ms |
304 KB |
Output is correct |
28 |
Correct |
8 ms |
308 KB |
Output is correct |
29 |
Correct |
20 ms |
208 KB |
Output is correct |
30 |
Correct |
46 ms |
300 KB |
Output is correct |
31 |
Correct |
30 ms |
328 KB |
Output is correct |
32 |
Correct |
26 ms |
304 KB |
Output is correct |
33 |
Correct |
39 ms |
324 KB |
Output is correct |
34 |
Correct |
34 ms |
296 KB |
Output is correct |
35 |
Correct |
42 ms |
316 KB |
Output is correct |
36 |
Correct |
29 ms |
296 KB |
Output is correct |
37 |
Correct |
30 ms |
304 KB |
Output is correct |
38 |
Correct |
37 ms |
300 KB |
Output is correct |
39 |
Correct |
65 ms |
308 KB |
Output is correct |
40 |
Correct |
17 ms |
208 KB |
Output is correct |
41 |
Correct |
9 ms |
312 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 |
1 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 |
23 ms |
292 KB |
Output is correct |
8 |
Correct |
12 ms |
332 KB |
Output is correct |
9 |
Partially correct |
97 ms |
372 KB |
Output is partially correct |
10 |
Partially correct |
131 ms |
380 KB |
Output is partially correct |
11 |
Correct |
15 ms |
304 KB |
Output is correct |
12 |
Correct |
42 ms |
336 KB |
Output is correct |
13 |
Partially correct |
118 ms |
284 KB |
Output is partially correct |
14 |
Partially correct |
118 ms |
380 KB |
Output is partially correct |
15 |
Partially correct |
68 ms |
372 KB |
Output is partially correct |
16 |
Partially correct |
68 ms |
368 KB |
Output is partially correct |
17 |
Partially correct |
78 ms |
372 KB |
Output is partially correct |
18 |
Partially correct |
78 ms |
284 KB |
Output is partially correct |
19 |
Partially correct |
77 ms |
368 KB |
Output is partially correct |
20 |
Partially correct |
101 ms |
372 KB |
Output is partially correct |
21 |
Partially correct |
106 ms |
376 KB |
Output is partially correct |
22 |
Partially correct |
95 ms |
336 KB |
Output is partially correct |
23 |
Partially correct |
83 ms |
308 KB |
Output is partially correct |
24 |
Correct |
40 ms |
336 KB |
Output is correct |
25 |
Correct |
41 ms |
352 KB |
Output is correct |
26 |
Correct |
18 ms |
328 KB |
Output is correct |
27 |
Partially correct |
98 ms |
372 KB |
Output is partially correct |
28 |
Partially correct |
97 ms |
500 KB |
Output is partially correct |
29 |
Partially correct |
79 ms |
368 KB |
Output is partially correct |
30 |
Partially correct |
119 ms |
372 KB |
Output is partially correct |
31 |
Partially correct |
96 ms |
296 KB |
Output is partially correct |
32 |
Partially correct |
95 ms |
308 KB |
Output is partially correct |
33 |
Partially correct |
97 ms |
344 KB |
Output is partially correct |
34 |
Partially correct |
96 ms |
296 KB |
Output is partially correct |
35 |
Partially correct |
73 ms |
292 KB |
Output is partially correct |
36 |
Partially correct |
99 ms |
292 KB |
Output is partially correct |
37 |
Partially correct |
84 ms |
364 KB |
Output is partially correct |
38 |
Partially correct |
111 ms |
292 KB |
Output is partially correct |
39 |
Partially correct |
85 ms |
292 KB |
Output is partially correct |
40 |
Partially correct |
73 ms |
376 KB |
Output is partially correct |
41 |
Partially correct |
100 ms |
376 KB |
Output is partially correct |
42 |
Partially correct |
82 ms |
380 KB |
Output is partially correct |
43 |
Partially correct |
17 ms |
316 KB |
Output is partially correct |
44 |
Partially correct |
64 ms |
376 KB |
Output is partially correct |
45 |
Correct |
36 ms |
284 KB |
Output is correct |
46 |
Correct |
48 ms |
332 KB |
Output is correct |
47 |
Correct |
51 ms |
332 KB |
Output is correct |
48 |
Correct |
35 ms |
320 KB |
Output is correct |