#include "insects.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) begin(a), end(a)
using vi = vector<int>;
int n, D;
set<int> S;
map<set<int>,int> M;
bool move_in(int i){
if(S.count(i)) return 0;
S.insert(i); move_inside(i);
return 1;
}
bool move_out(int i){
if(!S.count(i)) return 0;
S.erase(i); move_outside(i);
return 1;
}
int press(){
if(sz(S)==1) return 1;
if(M.count(S)) return M[S];
return M[S] = press_button();
}
int min_cardinality(int N) {
n = N; D = N;
vector<int> xd(n,0); iota(all(xd),0);
random_shuffle(all(xd));
for(int i = 0; i < n; i++){
move_in(xd[i]);
if(press()>1) move_out(xd[i]), D--;
}
for(int i = 0; i < n; i++) move_out(xd[i]);
int l = 1, r = n;
while(l<r){
int mid = (l+r+1)/2, tot=n;
vi undo; undo.clear();
for(int i = 0; i < n; i++){
if(!move_in(xd[i])) continue;
if(press()>mid) move_out(xd[i]), tot--;
else undo.pb(xd[i]);
}
if(tot==D*mid) l = mid;
else{
for(auto u : undo) move_out(u);
r=mid-1;
}
}
return l;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
6 ms |
2468 KB |
Output is correct |
7 |
Correct |
8 ms |
1368 KB |
Output is correct |
8 |
Correct |
7 ms |
1880 KB |
Output is correct |
9 |
Correct |
13 ms |
3844 KB |
Output is correct |
10 |
Correct |
10 ms |
2136 KB |
Output is correct |
11 |
Correct |
14 ms |
5212 KB |
Output is correct |
12 |
Correct |
11 ms |
2896 KB |
Output is correct |
13 |
Correct |
11 ms |
2904 KB |
Output is correct |
14 |
Correct |
10 ms |
3596 KB |
Output is correct |
15 |
Correct |
11 ms |
3928 KB |
Output is correct |
16 |
Correct |
11 ms |
4132 KB |
Output is correct |
17 |
Correct |
10 ms |
3416 KB |
Output is correct |
18 |
Correct |
15 ms |
3928 KB |
Output is correct |
19 |
Correct |
17 ms |
4176 KB |
Output is correct |
20 |
Correct |
16 ms |
3248 KB |
Output is correct |
21 |
Correct |
14 ms |
3416 KB |
Output is correct |
22 |
Correct |
11 ms |
2904 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
6 ms |
2468 KB |
Output is correct |
7 |
Correct |
8 ms |
1368 KB |
Output is correct |
8 |
Correct |
7 ms |
1880 KB |
Output is correct |
9 |
Correct |
13 ms |
3844 KB |
Output is correct |
10 |
Correct |
10 ms |
2136 KB |
Output is correct |
11 |
Correct |
14 ms |
5212 KB |
Output is correct |
12 |
Correct |
11 ms |
2896 KB |
Output is correct |
13 |
Correct |
11 ms |
2904 KB |
Output is correct |
14 |
Correct |
10 ms |
3596 KB |
Output is correct |
15 |
Correct |
11 ms |
3928 KB |
Output is correct |
16 |
Correct |
11 ms |
4132 KB |
Output is correct |
17 |
Correct |
10 ms |
3416 KB |
Output is correct |
18 |
Correct |
15 ms |
3928 KB |
Output is correct |
19 |
Correct |
17 ms |
4176 KB |
Output is correct |
20 |
Correct |
16 ms |
3248 KB |
Output is correct |
21 |
Correct |
14 ms |
3416 KB |
Output is correct |
22 |
Correct |
11 ms |
2904 KB |
Output is correct |
23 |
Correct |
125 ms |
54864 KB |
Output is correct |
24 |
Correct |
306 ms |
24068 KB |
Output is correct |
25 |
Correct |
173 ms |
27468 KB |
Output is correct |
26 |
Correct |
355 ms |
108080 KB |
Output is correct |
27 |
Correct |
142 ms |
38740 KB |
Output is correct |
28 |
Correct |
417 ms |
141080 KB |
Output is correct |
29 |
Correct |
224 ms |
57968 KB |
Output is correct |
30 |
Correct |
300 ms |
62072 KB |
Output is correct |
31 |
Correct |
232 ms |
83076 KB |
Output is correct |
32 |
Correct |
242 ms |
85504 KB |
Output is correct |
33 |
Correct |
277 ms |
92624 KB |
Output is correct |
34 |
Correct |
278 ms |
79316 KB |
Output is correct |
35 |
Correct |
286 ms |
92152 KB |
Output is correct |
36 |
Correct |
296 ms |
95532 KB |
Output is correct |
37 |
Correct |
311 ms |
95564 KB |
Output is correct |
38 |
Correct |
311 ms |
83916 KB |
Output is correct |
39 |
Correct |
303 ms |
78236 KB |
Output is correct |
40 |
Correct |
324 ms |
76616 KB |
Output is correct |
41 |
Correct |
343 ms |
79216 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Partially correct |
0 ms |
344 KB |
Output is partially correct |
7 |
Correct |
613 ms |
219040 KB |
Output is correct |
8 |
Execution timed out |
2351 ms |
94808 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |