#include "doll.h"
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
std::set<int> sss;
void create_circuit(int M, std::vector<int> A) {
int n = A.size();
vector<int> C(M + 1);
//C[0] = 1;
//C[1] = -1;
//C[2] = 1;
//C[3] = 0;
//C[4] = 0;
int sw = -1;
int xxx = 1;
while(xxx < 1000000){
sss.insert(xxx);
xxx *= 2;
}
vector<int> X, Y;
// X.push_back(2);
//Y.push_back(3);
vector<int> target[M+1];
for(int i = 0;i < n-1;i++){
target[A[i]].push_back(A[i+1]);
}
target[A[n-1]].push_back(0);
target[0].push_back(A[0]);
map<int, ii> mm;
for(int i = 0;i <= M;i++){
//printf("%d: ",i);
if(target[i].size() == 0) C[i] = 0;
else if(target[i].size() == 1) C[i] = target[i][0];
else{
int nn = *sss.lower_bound(target[i].size());
int tree[2 * nn];
tree[0] = 0;
for(int j = nn;j < 2 * nn;j++){
int l = j;
int v = 0;
while(l > 1){
v *= 2;
if(l % 2 == 1) v++;
l /= 2;
}
tree[j] = v;
}
for(int j = 1;j < nn;j++){
tree[j] = sw;
sw--;
}
map<int,int> dis;
for(int j = nn;j < 2 * nn;j++){
if(j - nn < nn-target[i].size()) tree[j] = tree[1];
else dis[tree[j]] = j;
//else tree[j] = target[i][tree[j] - (nn - target[i].size())];
}
int c = 0;
for(map<int,int>::iterator it = dis.begin();it != dis.end();it++){
tree[it->second] = target[i][c];
c++;
}
//for(int j = 0;j < 2 * nn;j++){
// printf("%d ",tree[j]);
//}
for(int j = 1;j < nn;j++){
mm[tree[j]] = ii(tree[j*2],tree[j*2+1]);
}
C[i] = tree[1];
}
//printf("\n");
}
for(map<int,ii>::iterator it = mm.begin();it != mm.end();it++){
X.push_back(it->second.first);
Y.push_back(it->second.second);
}
reverse(X.begin(),X.end());
reverse(Y.begin(),Y.end());
/*
for(int i = 0;i < C.size();i++){
printf("%d ",C[i]);
}
printf("\n");
for(int i = 0;i < X.size();i++){
printf("%d %d\n",X[i],Y[i]);
}
*/
answer(C, X, Y);
}
Compilation message
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:58:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | if(j - nn < nn-target[i].size()) tree[j] = tree[1];
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
32 ms |
6348 KB |
Output is correct |
3 |
Correct |
34 ms |
5068 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
13 ms |
3788 KB |
Output is correct |
6 |
Correct |
42 ms |
7628 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 |
32 ms |
6348 KB |
Output is correct |
3 |
Correct |
34 ms |
5068 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
13 ms |
3788 KB |
Output is correct |
6 |
Correct |
42 ms |
7628 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
82 ms |
11296 KB |
Output is correct |
9 |
Correct |
99 ms |
11352 KB |
Output is correct |
10 |
Correct |
127 ms |
17232 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 |
32 ms |
6348 KB |
Output is correct |
3 |
Correct |
34 ms |
5068 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
13 ms |
3788 KB |
Output is correct |
6 |
Correct |
42 ms |
7628 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
82 ms |
11296 KB |
Output is correct |
9 |
Correct |
99 ms |
11352 KB |
Output is correct |
10 |
Correct |
127 ms |
17232 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 |
201 ms |
23452 KB |
Output is correct |
15 |
Correct |
102 ms |
11900 KB |
Output is correct |
16 |
Correct |
145 ms |
18076 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 |
151 ms |
20048 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 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
1 ms |
204 KB |
Output is partially correct |
2 |
Correct |
158 ms |
17328 KB |
Output is correct |
3 |
Partially correct |
212 ms |
30520 KB |
Output is partially correct |
4 |
Partially correct |
311 ms |
31508 KB |
Output is partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
1 ms |
204 KB |
Output is partially correct |
2 |
Correct |
158 ms |
17328 KB |
Output is correct |
3 |
Partially correct |
212 ms |
30520 KB |
Output is partially correct |
4 |
Partially correct |
311 ms |
31508 KB |
Output is partially correct |
5 |
Partially correct |
227 ms |
29548 KB |
Output is partially correct |
6 |
Partially correct |
257 ms |
33272 KB |
Output is partially correct |
7 |
Partially correct |
258 ms |
31944 KB |
Output is partially correct |
8 |
Partially correct |
283 ms |
35452 KB |
Output is partially correct |
9 |
Partially correct |
195 ms |
26440 KB |
Output is partially correct |
10 |
Partially correct |
305 ms |
38792 KB |
Output is partially correct |
11 |
Partially correct |
276 ms |
37888 KB |
Output is partially correct |
12 |
Partially correct |
195 ms |
25048 KB |
Output is partially correct |
13 |
Partially correct |
178 ms |
21936 KB |
Output is partially correct |
14 |
Partially correct |
147 ms |
20948 KB |
Output is partially correct |
15 |
Partially correct |
138 ms |
19428 KB |
Output is partially correct |
16 |
Partially correct |
5 ms |
844 KB |
Output is partially correct |
17 |
Partially correct |
134 ms |
19468 KB |
Output is partially correct |
18 |
Partially correct |
183 ms |
19668 KB |
Output is partially correct |
19 |
Partially correct |
149 ms |
21104 KB |
Output is partially correct |
20 |
Partially correct |
201 ms |
26324 KB |
Output is partially correct |
21 |
Partially correct |
295 ms |
32736 KB |
Output is partially correct |
22 |
Partially correct |
179 ms |
25008 KB |
Output is partially correct |