#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) {
switch_cnt += sz-1;
offset += sz-1;
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:56:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for (int i=0; i+1<A.size(); ++i) go[A[i]].push_back(A[i+1]);
| ~~~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
23 ms |
6340 KB |
Output is correct |
3 |
Correct |
19 ms |
5176 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
10 ms |
3796 KB |
Output is correct |
6 |
Correct |
30 ms |
7636 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
23 ms |
6340 KB |
Output is correct |
3 |
Correct |
19 ms |
5176 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
10 ms |
3796 KB |
Output is correct |
6 |
Correct |
30 ms |
7636 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
40 ms |
7164 KB |
Output is correct |
9 |
Correct |
60 ms |
9592 KB |
Output is correct |
10 |
Correct |
77 ms |
12536 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
23 ms |
6340 KB |
Output is correct |
3 |
Correct |
19 ms |
5176 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
10 ms |
3796 KB |
Output is correct |
6 |
Correct |
30 ms |
7636 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
40 ms |
7164 KB |
Output is correct |
9 |
Correct |
60 ms |
9592 KB |
Output is correct |
10 |
Correct |
77 ms |
12536 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
308 KB |
Output is correct |
14 |
Incorrect |
71 ms |
10908 KB |
wrong motion |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
wrong motion |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
wrong motion |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
wrong motion |
2 |
Halted |
0 ms |
0 KB |
- |