#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>;
using ll = long long;
using ar2 = array<ll,2>;
using ar3 = array<ll,3>;
const int mxN = (int)2e3+10;
int n, cnt[mxN];
vi v, others;
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; int ans = 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()==2) 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;
}
Compilation message
insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:36:13: warning: unused variable 'ans' [-Wunused-variable]
36 | n = N; int ans = n, D=n;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
596 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 |
8 ms |
2604 KB |
Output is correct |
7 |
Correct |
10 ms |
1368 KB |
Output is correct |
8 |
Correct |
8 ms |
2024 KB |
Output is correct |
9 |
Correct |
16 ms |
3728 KB |
Output is correct |
10 |
Correct |
10 ms |
2000 KB |
Output is correct |
11 |
Correct |
19 ms |
4892 KB |
Output is correct |
12 |
Correct |
14 ms |
2904 KB |
Output is correct |
13 |
Correct |
11 ms |
2904 KB |
Output is correct |
14 |
Correct |
10 ms |
3416 KB |
Output is correct |
15 |
Correct |
11 ms |
3928 KB |
Output is correct |
16 |
Correct |
13 ms |
4516 KB |
Output is correct |
17 |
Correct |
15 ms |
3416 KB |
Output is correct |
18 |
Correct |
16 ms |
3812 KB |
Output is correct |
19 |
Correct |
14 ms |
4216 KB |
Output is correct |
20 |
Correct |
13 ms |
3248 KB |
Output is correct |
21 |
Correct |
12 ms |
3416 KB |
Output is correct |
22 |
Correct |
11 ms |
2904 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
596 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 |
8 ms |
2604 KB |
Output is correct |
7 |
Correct |
10 ms |
1368 KB |
Output is correct |
8 |
Correct |
8 ms |
2024 KB |
Output is correct |
9 |
Correct |
16 ms |
3728 KB |
Output is correct |
10 |
Correct |
10 ms |
2000 KB |
Output is correct |
11 |
Correct |
19 ms |
4892 KB |
Output is correct |
12 |
Correct |
14 ms |
2904 KB |
Output is correct |
13 |
Correct |
11 ms |
2904 KB |
Output is correct |
14 |
Correct |
10 ms |
3416 KB |
Output is correct |
15 |
Correct |
11 ms |
3928 KB |
Output is correct |
16 |
Correct |
13 ms |
4516 KB |
Output is correct |
17 |
Correct |
15 ms |
3416 KB |
Output is correct |
18 |
Correct |
16 ms |
3812 KB |
Output is correct |
19 |
Correct |
14 ms |
4216 KB |
Output is correct |
20 |
Correct |
13 ms |
3248 KB |
Output is correct |
21 |
Correct |
12 ms |
3416 KB |
Output is correct |
22 |
Correct |
11 ms |
2904 KB |
Output is correct |
23 |
Correct |
131 ms |
54984 KB |
Output is correct |
24 |
Correct |
321 ms |
23888 KB |
Output is correct |
25 |
Correct |
214 ms |
27468 KB |
Output is correct |
26 |
Correct |
335 ms |
108108 KB |
Output is correct |
27 |
Correct |
146 ms |
39080 KB |
Output is correct |
28 |
Correct |
333 ms |
141028 KB |
Output is correct |
29 |
Correct |
209 ms |
58184 KB |
Output is correct |
30 |
Correct |
273 ms |
62008 KB |
Output is correct |
31 |
Correct |
228 ms |
83156 KB |
Output is correct |
32 |
Correct |
250 ms |
85628 KB |
Output is correct |
33 |
Correct |
274 ms |
92772 KB |
Output is correct |
34 |
Correct |
248 ms |
79104 KB |
Output is correct |
35 |
Correct |
345 ms |
92060 KB |
Output is correct |
36 |
Correct |
304 ms |
95604 KB |
Output is correct |
37 |
Correct |
326 ms |
95536 KB |
Output is correct |
38 |
Correct |
330 ms |
84064 KB |
Output is correct |
39 |
Correct |
299 ms |
78012 KB |
Output is correct |
40 |
Correct |
319 ms |
76740 KB |
Output is correct |
41 |
Correct |
350 ms |
79332 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 |
0 ms |
344 KB |
Output is correct |
6 |
Partially correct |
0 ms |
344 KB |
Output is partially correct |
7 |
Correct |
582 ms |
218872 KB |
Output is correct |
8 |
Execution timed out |
2346 ms |
94932 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |