// Be name khoda //
#include "insects.h"
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define debug(x) cerr << "(" << (#x) << "): " << (x) << endl;
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
const int mod = 1e9 + 9;
const int maxn5 = 1e5 + 10;
int dif, n, pw[maxn5], per[maxn5], hsh = 0;
bool mark[maxn5];
vector <int> av;
map <int, int> asked;
void fix(int &a){
if(a < 0)
a += mod;
if(a >= mod)
a -= mod;
}
void mmove_outside(int x){
x = per[x];
move_outside(x);
fix(hsh -= pw[x]);
}
void mmove_inside(int x){
x = per[x];
move_inside(x);
fix(hsh += pw[x]);
}
int ppress_button(){
if(asked.find(hsh) == asked.end())
asked[hsh] = press_button();
return asked[hsh];
}
int find_all_same(int id){
mark[id] = true;
mmove_inside(id);
int cnt = 1;
for(int i = 0; i < n; i++) if(!mark[i]){
mmove_inside(i);
if(ppress_button() == 2){
mark[i] = true;
cnt++;
}
mmove_outside(i);
}
mmove_outside(id);
return cnt;
}
int count_dif(){
av.clear();
hsh = 0;
for(int i = 0; i < n; i++){
mmove_inside(i);
av.pb(i);
if(ppress_button() == 2){
mmove_outside(i);
av.pop_back();
}
}
for(auto u : av)
mmove_outside(u);
return av.size();
}
bool check(int x){
av.clear();
hsh = 0;
for(int i = 0; i < n; i++){
av.pb(i);
mmove_inside(i);
if(i + 1 > x && ppress_button() > x){
mmove_outside(i);
av.pop_back();
}
if(int(av.size()) == x * dif)
break;
if(int(av.size()) + n - i - 1 < x * dif)
break;
}
for(auto u : av)
mmove_outside(u);
return int(av.size()) == x * dif;
}
int min_cardinality(int N) {
n = N;
pw[0] = 1;
for(int i = 0; i < n; i++){
per[i] = i;
if(i)
pw[i] = pw[i - 1] * 7ll % mod;
}
shuffle(per, per + n, rng);
dif = count_dif();
if(dif == 1)
return n;
if(dif <= 8){
int mn = n;
for(int i = 0; i < n; i++) if(!mark[i]){
mn = min(mn, find_all_same(i));
if(mn == 1)
return 1;
}
return mn;
}
int lo = 1, hi = n / dif + 1;
while(hi - lo > 1){
int mid = (lo + hi) >> 1;
if(check(mid))
lo = mid;
else
hi = mid;
}
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 |
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 |
2 ms |
208 KB |
Output is correct |
7 |
Correct |
2 ms |
208 KB |
Output is correct |
8 |
Correct |
4 ms |
336 KB |
Output is correct |
9 |
Correct |
5 ms |
336 KB |
Output is correct |
10 |
Correct |
3 ms |
208 KB |
Output is correct |
11 |
Correct |
2 ms |
208 KB |
Output is correct |
12 |
Correct |
7 ms |
336 KB |
Output is correct |
13 |
Correct |
5 ms |
336 KB |
Output is correct |
14 |
Correct |
5 ms |
336 KB |
Output is correct |
15 |
Correct |
10 ms |
336 KB |
Output is correct |
16 |
Correct |
8 ms |
336 KB |
Output is correct |
17 |
Correct |
4 ms |
340 KB |
Output is correct |
18 |
Correct |
5 ms |
336 KB |
Output is correct |
19 |
Correct |
4 ms |
336 KB |
Output is correct |
20 |
Correct |
3 ms |
336 KB |
Output is correct |
21 |
Correct |
3 ms |
332 KB |
Output is correct |
22 |
Correct |
2 ms |
208 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 |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
2 ms |
208 KB |
Output is correct |
7 |
Correct |
2 ms |
208 KB |
Output is correct |
8 |
Correct |
4 ms |
336 KB |
Output is correct |
9 |
Correct |
5 ms |
336 KB |
Output is correct |
10 |
Correct |
3 ms |
208 KB |
Output is correct |
11 |
Correct |
2 ms |
208 KB |
Output is correct |
12 |
Correct |
7 ms |
336 KB |
Output is correct |
13 |
Correct |
5 ms |
336 KB |
Output is correct |
14 |
Correct |
5 ms |
336 KB |
Output is correct |
15 |
Correct |
10 ms |
336 KB |
Output is correct |
16 |
Correct |
8 ms |
336 KB |
Output is correct |
17 |
Correct |
4 ms |
340 KB |
Output is correct |
18 |
Correct |
5 ms |
336 KB |
Output is correct |
19 |
Correct |
4 ms |
336 KB |
Output is correct |
20 |
Correct |
3 ms |
336 KB |
Output is correct |
21 |
Correct |
3 ms |
332 KB |
Output is correct |
22 |
Correct |
2 ms |
208 KB |
Output is correct |
23 |
Correct |
6 ms |
336 KB |
Output is correct |
24 |
Correct |
7 ms |
336 KB |
Output is correct |
25 |
Correct |
22 ms |
616 KB |
Output is correct |
26 |
Correct |
31 ms |
452 KB |
Output is correct |
27 |
Correct |
11 ms |
336 KB |
Output is correct |
28 |
Correct |
6 ms |
336 KB |
Output is correct |
29 |
Correct |
18 ms |
404 KB |
Output is correct |
30 |
Correct |
35 ms |
520 KB |
Output is correct |
31 |
Correct |
26 ms |
460 KB |
Output is correct |
32 |
Correct |
35 ms |
640 KB |
Output is correct |
33 |
Correct |
32 ms |
516 KB |
Output is correct |
34 |
Correct |
23 ms |
440 KB |
Output is correct |
35 |
Correct |
25 ms |
384 KB |
Output is correct |
36 |
Correct |
37 ms |
492 KB |
Output is correct |
37 |
Correct |
23 ms |
472 KB |
Output is correct |
38 |
Correct |
21 ms |
608 KB |
Output is correct |
39 |
Correct |
24 ms |
464 KB |
Output is correct |
40 |
Correct |
11 ms |
336 KB |
Output is correct |
41 |
Correct |
6 ms |
356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 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 |
0 ms |
208 KB |
Output is correct |
7 |
Correct |
16 ms |
372 KB |
Output is correct |
8 |
Correct |
13 ms |
336 KB |
Output is correct |
9 |
Partially correct |
41 ms |
560 KB |
Output is partially correct |
10 |
Partially correct |
73 ms |
716 KB |
Output is partially correct |
11 |
Correct |
19 ms |
392 KB |
Output is correct |
12 |
Correct |
13 ms |
348 KB |
Output is correct |
13 |
Partially correct |
32 ms |
600 KB |
Output is partially correct |
14 |
Partially correct |
84 ms |
784 KB |
Output is partially correct |
15 |
Partially correct |
55 ms |
584 KB |
Output is partially correct |
16 |
Partially correct |
75 ms |
772 KB |
Output is partially correct |
17 |
Partially correct |
50 ms |
564 KB |
Output is partially correct |
18 |
Partially correct |
48 ms |
580 KB |
Output is partially correct |
19 |
Partially correct |
37 ms |
660 KB |
Output is partially correct |
20 |
Partially correct |
71 ms |
768 KB |
Output is partially correct |
21 |
Partially correct |
59 ms |
692 KB |
Output is partially correct |
22 |
Partially correct |
66 ms |
700 KB |
Output is partially correct |
23 |
Partially correct |
49 ms |
584 KB |
Output is partially correct |
24 |
Correct |
34 ms |
564 KB |
Output is correct |
25 |
Correct |
23 ms |
452 KB |
Output is correct |
26 |
Correct |
12 ms |
336 KB |
Output is correct |
27 |
Partially correct |
48 ms |
564 KB |
Output is partially correct |
28 |
Partially correct |
37 ms |
580 KB |
Output is partially correct |
29 |
Partially correct |
37 ms |
564 KB |
Output is partially correct |
30 |
Partially correct |
42 ms |
576 KB |
Output is partially correct |
31 |
Partially correct |
52 ms |
1048 KB |
Output is partially correct |
32 |
Partially correct |
58 ms |
796 KB |
Output is partially correct |
33 |
Partially correct |
50 ms |
720 KB |
Output is partially correct |
34 |
Partially correct |
56 ms |
736 KB |
Output is partially correct |
35 |
Partially correct |
30 ms |
624 KB |
Output is partially correct |
36 |
Partially correct |
54 ms |
724 KB |
Output is partially correct |
37 |
Partially correct |
55 ms |
628 KB |
Output is partially correct |
38 |
Partially correct |
52 ms |
700 KB |
Output is partially correct |
39 |
Partially correct |
48 ms |
560 KB |
Output is partially correct |
40 |
Partially correct |
44 ms |
604 KB |
Output is partially correct |
41 |
Partially correct |
37 ms |
588 KB |
Output is partially correct |
42 |
Partially correct |
37 ms |
624 KB |
Output is partially correct |
43 |
Correct |
10 ms |
484 KB |
Output is correct |
44 |
Correct |
25 ms |
456 KB |
Output is correct |
45 |
Correct |
37 ms |
460 KB |
Output is correct |
46 |
Correct |
13 ms |
464 KB |
Output is correct |
47 |
Correct |
13 ms |
416 KB |
Output is correct |
48 |
Correct |
15 ms |
584 KB |
Output is correct |