#include "insects.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
vector<int> cur_v, perm;
map<vector<int>, int> qry_mem;
int qry(vector<int> v) {
sort(v.begin(), v.end());
vector<int> chng;
set_symmetric_difference(v.begin(), v.end(), cur_v.begin(), cur_v.end(), back_inserter(chng));
for (int i : chng) {
if (binary_search(v.begin(), v.end(), i)) {
move_inside(perm[i]);
} else {
move_outside(perm[i]);
}
}
cur_v = v;
if (qry_mem.find(cur_v) != qry_mem.end()) {
return qry_mem[cur_v];
}
return qry_mem[cur_v] = press_button();
}
mt19937 rng(998244353);
int min_cardinality(int N) {
perm.resize(N);
iota(perm.begin(), perm.end(), 0);
shuffle(perm.begin(), perm.end(), rng);
vector<int> rep, cnt(N, 0), lnk(N, -1);
for (int i = 0; i < N; i++) {
{
shuffle(rep.begin(), rep.end(), rng);
int lo = 0, hi = (int)rep.size() - 1;
while (lo <= hi) {
int mid = (lo + hi) / 2;
vector<int> cur;
for (int j = 0; j <= mid; j++) {
cur.pb(rep[j]);
}
int q1 = qry(cur);
cur.pb(i);
int q2 = qry(cur);
if (q1 != q2) {
lnk[i] = rep[mid];
hi = mid - 1;
} else {
lo = mid + 1;
}
}
}
if (lnk[i] == -1) {
rep.pb(i);
}
}
int ret = N;
for (int i = N - 1; i >= 0; i--) {
cnt[i]++;
if (lnk[i] == -1) {
ret = min(ret, cnt[i]);
} else {
cnt[lnk[i]] += cnt[i];
}
}
return ret;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
37 ms |
1452 KB |
Output is correct |
8 |
Correct |
11 ms |
456 KB |
Output is correct |
9 |
Correct |
15 ms |
336 KB |
Output is correct |
10 |
Correct |
2 ms |
208 KB |
Output is correct |
11 |
Correct |
17 ms |
764 KB |
Output is correct |
12 |
Correct |
6 ms |
336 KB |
Output is correct |
13 |
Correct |
8 ms |
336 KB |
Output is correct |
14 |
Correct |
7 ms |
336 KB |
Output is correct |
15 |
Correct |
8 ms |
320 KB |
Output is correct |
16 |
Correct |
11 ms |
404 KB |
Output is correct |
17 |
Correct |
14 ms |
348 KB |
Output is correct |
18 |
Correct |
15 ms |
416 KB |
Output is correct |
19 |
Correct |
13 ms |
456 KB |
Output is correct |
20 |
Correct |
18 ms |
620 KB |
Output is correct |
21 |
Correct |
26 ms |
924 KB |
Output is correct |
22 |
Correct |
29 ms |
948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
37 ms |
1452 KB |
Output is correct |
8 |
Correct |
11 ms |
456 KB |
Output is correct |
9 |
Correct |
15 ms |
336 KB |
Output is correct |
10 |
Correct |
2 ms |
208 KB |
Output is correct |
11 |
Correct |
17 ms |
764 KB |
Output is correct |
12 |
Correct |
6 ms |
336 KB |
Output is correct |
13 |
Correct |
8 ms |
336 KB |
Output is correct |
14 |
Correct |
7 ms |
336 KB |
Output is correct |
15 |
Correct |
8 ms |
320 KB |
Output is correct |
16 |
Correct |
11 ms |
404 KB |
Output is correct |
17 |
Correct |
14 ms |
348 KB |
Output is correct |
18 |
Correct |
15 ms |
416 KB |
Output is correct |
19 |
Correct |
13 ms |
456 KB |
Output is correct |
20 |
Correct |
18 ms |
620 KB |
Output is correct |
21 |
Correct |
26 ms |
924 KB |
Output is correct |
22 |
Correct |
29 ms |
948 KB |
Output is correct |
23 |
Correct |
10 ms |
336 KB |
Output is correct |
24 |
Incorrect |
114 ms |
4808 KB |
Too many queries. |
25 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
208 KB |
Output is correct |
5 |
Correct |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
20 ms |
524 KB |
Output is correct |
8 |
Incorrect |
95 ms |
4924 KB |
Too many queries. |
9 |
Halted |
0 ms |
0 KB |
- |