#include <bits/stdc++.h>
using namespace std;
#include "doll.h"
#define all(x) x.begin(), x.end()
#define mp make_pair
#define mt make_tuple
#define x first
#define y second
const int MAX = 1e9;
vector<int> x, y, arr;
int solve(vector<int> idx) {
assert(idx.size());
if ((int)count(all(idx), -1) == (int)idx.size()) {
return -1;
}
if (idx.size() == 1) {
return idx[0];
}
x.push_back(0), y.push_back(0);
int v = -(int)x.size();
// cout << v << ": ";
// for (int e : idx) {
// cout << e << " ";
// }
// cout << endl;
vector<int> lef, rig;
for (int e : idx) {
if (2 * lef.size() + 2 <= idx.size()) {
lef.push_back(e);
} else {
rig.push_back(e);
}
}
// cout << "div " << idx.size() << " " << lef.size() << " " << rig.size() << endl;
// for (int i = 0; i < (int)idx.size(); ++i) {
// (i % 2 ? rig : lef).push_back(idx[i]);
// }
assert(0 <= -1 - v && -1 - v < (int)x.size());
assert(0 <= -1 - v && -1 - v < (int)y.size());
int a = solve(lef), b = solve(rig);
x[-1 - v] = a;
y[-1 - v] = b;
return v;
}
bool bit(int m, int i) {
return (m >> i) & 1;
}
void create_circuit(int m, vector<int> a) {
arr = a;
int p = (int)a.size() + 1;
while (p & (p - 1)) {
++p;
}
vector<int> c(m + 1, -1), idx(p);
iota(all(idx), 0);
sort(all(idx), [&](int xx, int yy) {
for (int i = 0; i < 20; ++i) {
if (bit(xx ^ yy, i)) {
return bit(yy, i);
}
}
return false;
});
// for (int e : idx) {
// cout << e << " ";
// }
// cout << endl;
for (int i = 0; i < p - (int)a.size() - 1; ++i) {
idx[i] = -1;
}
idx.back() = 0;
vector<pair<int, int>> srt;
for (int i = p - (int)a.size() - 1; i < p - 1; ++i) {
srt.emplace_back(idx[i], i);
}
sort(all(srt));
assert((int)srt.size() == (int)a.size());
for (int i = 0; i < (int)srt.size(); ++i) {
idx[srt[i].y] = a[i];
}
// for (int &e : idx) {
// if (e < (int)a.size()) {
// e = a[e];
// } else if (e == p - 1) {
// e = 0;
// } else {
// e = -1;
// }
// cout << e << " ";
// }
// cout << endl;
int root = solve(idx);
assert(root == -1);
// cout << "===" << endl;
// for (int e : x) {
// cout << e << " ";
// }
// cout << endl;
// for (int e : y) {
// cout << e << " ";
// }
// cout << endl;
answer(c, x, y);
}
#ifdef LC
#include "grader.cpp"
#endif
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
108 ms |
5688 KB |
Output is correct |
3 |
Correct |
101 ms |
5560 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
12 ms |
1356 KB |
Output is correct |
6 |
Correct |
128 ms |
6836 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
108 ms |
5688 KB |
Output is correct |
3 |
Correct |
101 ms |
5560 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
12 ms |
1356 KB |
Output is correct |
6 |
Correct |
128 ms |
6836 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
198 ms |
10404 KB |
Output is correct |
9 |
Correct |
229 ms |
10656 KB |
Output is correct |
10 |
Correct |
296 ms |
13124 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
108 ms |
5688 KB |
Output is correct |
3 |
Correct |
101 ms |
5560 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
12 ms |
1356 KB |
Output is correct |
6 |
Correct |
128 ms |
6836 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
198 ms |
10404 KB |
Output is correct |
9 |
Correct |
229 ms |
10656 KB |
Output is correct |
10 |
Correct |
296 ms |
13124 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
261 ms |
13100 KB |
Output is correct |
15 |
Correct |
210 ms |
10348 KB |
Output is correct |
16 |
Correct |
286 ms |
12964 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
279 ms |
13060 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
204 KB |
Output is correct |
2 |
Correct |
205 ms |
10212 KB |
Output is correct |
3 |
Correct |
246 ms |
10264 KB |
Output is correct |
4 |
Correct |
247 ms |
12736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
204 KB |
Output is correct |
2 |
Correct |
205 ms |
10212 KB |
Output is correct |
3 |
Correct |
246 ms |
10264 KB |
Output is correct |
4 |
Correct |
247 ms |
12736 KB |
Output is correct |
5 |
Correct |
254 ms |
12884 KB |
Output is correct |
6 |
Correct |
251 ms |
12852 KB |
Output is correct |
7 |
Correct |
263 ms |
12972 KB |
Output is correct |
8 |
Correct |
248 ms |
12796 KB |
Output is correct |
9 |
Correct |
194 ms |
10268 KB |
Output is correct |
10 |
Correct |
261 ms |
12832 KB |
Output is correct |
11 |
Correct |
254 ms |
12728 KB |
Output is correct |
12 |
Correct |
190 ms |
10272 KB |
Output is correct |
13 |
Correct |
193 ms |
10216 KB |
Output is correct |
14 |
Correct |
195 ms |
10348 KB |
Output is correct |
15 |
Correct |
201 ms |
10260 KB |
Output is correct |
16 |
Correct |
6 ms |
588 KB |
Output is correct |
17 |
Correct |
148 ms |
7336 KB |
Output is correct |
18 |
Correct |
190 ms |
10268 KB |
Output is correct |
19 |
Correct |
197 ms |
10264 KB |
Output is correct |
20 |
Correct |
264 ms |
12836 KB |
Output is correct |
21 |
Correct |
312 ms |
12776 KB |
Output is correct |
22 |
Correct |
245 ms |
12740 KB |
Output is correct |