#include "doll.h"
#include<bits/stdc++.h>
using namespace std;
using ll = int;
void create_circuit(int M, std::vector<int> A) {
int N = A.size();
std::vector<int> C(M + 1);
C[0] = A[0];
for (int i = 1; i <= M; ++i) C[i]=0;
if (N == 1){
for (int i = 1; i <= M; ++i) C[i] = 0;
vector<int> X,Y;
answer(C, X, Y);
return;
}
vector<ll> ctr(M);
ll mxctr = 0;
for(ll i : A) ctr[i-1]++;
for(ll i : ctr) mxctr = max(mxctr,i);
if (mxctr == 1){
vector<int> X,Y;
A.push_back(0);
for(ll i = 0;i<N;i++) C[A[i]] = A[i+1];
answer(C, X, Y);
return;
}else if (mxctr == 2){
ll it = 0;
vector<ll> ptr(M);
for(ll i = 0;i<M;i++){
if (ctr[i]==2) ptr[i] = it++,C[i+1] = -1-ptr[i];
}
A.push_back(0);
vector<ll> X(it,-1),Y(it,-1);
for(ll i = 0;i<N;i++) {
if (ctr[A[i]-1] == 1) C[A[i]] = A[i+1];
else{
if(X[ptr[A[i]-1]] == -1)X[ptr[A[i]-1]] = A[i+1];
else Y[ptr[A[i]-1]] = A[i+1];
}
}
answer(C, X, Y);
return;
}
for (int i = 1; i <= M; ++i) {
C[i] = -1;
}
ll GN = 1<<(__lg(N-1)+1);
while (A.size()<GN) A.push_back(-1);
A.push_back(0);
vector<int> X(GN-1),Y(GN-1);
ll it = 0;
function<ll(ll,ll,ll)> dfs;
dfs = [&](ll cnt, ll st, ll lv){
if (cnt==1){
return A[st+1];
}
ll i = it++;
X[i] = dfs(cnt-cnt/2,st,lv+1);
Y[i] = dfs(cnt/2,st+(1<<lv),lv+1);
return -1-i;
};
dfs(GN,0,0);
if (X.size()==0){
for(ll &i : C) if (i==-1) i = 0;
}
answer(C, X, Y);
}
Compilation message
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:49:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'int'} [-Wsign-compare]
49 | while (A.size()<GN) A.push_back(-1);
| ~~~~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
16 ms |
2348 KB |
Output is correct |
3 |
Correct |
13 ms |
1844 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
9 ms |
1876 KB |
Output is correct |
6 |
Correct |
21 ms |
2636 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
16 ms |
2348 KB |
Output is correct |
3 |
Correct |
13 ms |
1844 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
9 ms |
1876 KB |
Output is correct |
6 |
Correct |
21 ms |
2636 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
34 ms |
4176 KB |
Output is correct |
9 |
Correct |
33 ms |
4272 KB |
Output is correct |
10 |
Correct |
50 ms |
6076 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
16 ms |
2348 KB |
Output is correct |
3 |
Correct |
13 ms |
1844 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
9 ms |
1876 KB |
Output is correct |
6 |
Correct |
21 ms |
2636 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
34 ms |
4176 KB |
Output is correct |
9 |
Correct |
33 ms |
4272 KB |
Output is correct |
10 |
Correct |
50 ms |
6076 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Incorrect |
83 ms |
9268 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
0 ms |
212 KB |
Output is partially correct |
2 |
Correct |
34 ms |
5080 KB |
Output is correct |
3 |
Partially correct |
62 ms |
8004 KB |
Output is partially correct |
4 |
Partially correct |
78 ms |
8228 KB |
Output is partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
0 ms |
212 KB |
Output is partially correct |
2 |
Correct |
34 ms |
5080 KB |
Output is correct |
3 |
Partially correct |
62 ms |
8004 KB |
Output is partially correct |
4 |
Partially correct |
78 ms |
8228 KB |
Output is partially correct |
5 |
Partially correct |
76 ms |
8840 KB |
Output is partially correct |
6 |
Partially correct |
82 ms |
8508 KB |
Output is partially correct |
7 |
Partially correct |
74 ms |
8632 KB |
Output is partially correct |
8 |
Partially correct |
76 ms |
8348 KB |
Output is partially correct |
9 |
Partially correct |
67 ms |
7960 KB |
Output is partially correct |
10 |
Partially correct |
72 ms |
8380 KB |
Output is partially correct |
11 |
Partially correct |
80 ms |
8240 KB |
Output is partially correct |
12 |
Partially correct |
61 ms |
8016 KB |
Output is partially correct |
13 |
Correct |
48 ms |
5780 KB |
Output is correct |
14 |
Partially correct |
68 ms |
8248 KB |
Output is partially correct |
15 |
Partially correct |
68 ms |
8400 KB |
Output is partially correct |
16 |
Partially correct |
3 ms |
596 KB |
Output is partially correct |
17 |
Correct |
38 ms |
5316 KB |
Output is correct |
18 |
Correct |
38 ms |
5256 KB |
Output is correct |
19 |
Partially correct |
59 ms |
8016 KB |
Output is partially correct |
20 |
Partially correct |
73 ms |
8244 KB |
Output is partially correct |
21 |
Partially correct |
84 ms |
8284 KB |
Output is partially correct |
22 |
Partially correct |
75 ms |
8280 KB |
Output is partially correct |