#include "doll.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int rev(int x, int sz) {
int k = 31 - __builtin_clz(sz);
int ret = 0;
for (int i=0; i<k; ++i) ret |= (1 << (k-1-i)) * ((x & (1 << i)) > 0);
// cout << x << ' ' << sz << ' ' << ret << endl;
return ret;
}
int switch_cnt = 0;
vector<int> c, x, y;
int build_single_circuit(vector<int> A) {
int root = -switch_cnt-1;
int n = A.size();
int offset = 0;
// cout << n << endl;
// for (int i: A) cout << i << ' ';
// cout << endl;
while (offset < n) {
int sz = 1 << (31 - __builtin_clz(n-offset));
// cout << switch_cnt << ' ' << n << ' ' << sz << ' ' << offset << endl;
for (int i=1; i<sz/2; ++i) {
x.push_back(-(switch_cnt + 2*i));
y.push_back(-(switch_cnt + 2*i+1));
}
for (int i=0; i<sz/2; ++i) {
x.push_back(A[offset + rev(2*i, sz)]);
// c[offset + rev(2*i, sz)] = -switch_cnt-1;
if (i+1 < sz/2) {
y.push_back(A[offset + rev(2*i+1, sz)]);
// c[offset + rev(2*i+1, sz)] = -switch_cnt-1;
}
}
if (n-offset == sz) {
y.push_back(A.back());
break;
} else {
switch_cnt += sz-1;
offset += sz-1;
y.push_back(-switch_cnt-1);
}
}
return root;
}
void create_circuit(int m, vector<int> A) {
vector<vector<int>> go(m+1);
for (int i=0; i+1<A.size(); ++i) go[A[i]].push_back(A[i+1]);
go[A.back()].push_back(0);
c.resize(m+1);
c[0] = A[0];
for (int i=1; i<=m; ++i) {
if (go[i].size() == 1) {
c[i] = go[i][0];
} else if (go[i].size() >= 2) {
c[i] = build_single_circuit(go[i]);
}
}
// for (int i: c) cout << i << ' ';
// cout << endl;
// for (int i: x) cout << i << ' ';
// cout << endl;
// for (int i: y) cout << i << ' ';
// cout << endl;
answer(c, x, y);
}
Compilation message
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:54:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | for (int i=0; i+1<A.size(); ++i) go[A[i]].push_back(A[i+1]);
| ~~~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
22 ms |
6824 KB |
Output is correct |
3 |
Correct |
19 ms |
5588 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
9 ms |
3796 KB |
Output is correct |
6 |
Correct |
32 ms |
8428 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
22 ms |
6824 KB |
Output is correct |
3 |
Correct |
19 ms |
5588 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
9 ms |
3796 KB |
Output is correct |
6 |
Correct |
32 ms |
8428 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Incorrect |
42 ms |
8108 KB |
wrong motion |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
22 ms |
6824 KB |
Output is correct |
3 |
Correct |
19 ms |
5588 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
9 ms |
3796 KB |
Output is correct |
6 |
Correct |
32 ms |
8428 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Incorrect |
42 ms |
8108 KB |
wrong motion |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
wrong motion |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
300 KB |
wrong motion |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
300 KB |
wrong motion |
2 |
Halted |
0 ms |
0 KB |
- |