#include<bits/stdc++.h>
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define pb push_back
#include "doll.h"
typedef long long ll;
typedef long double ld;
using namespace std;
const int N = (int)5e5 + 10;
int lst = 0;
vector<int>trans[N];
int m;
int x[N],y[N];
int was = -1;
int build(vector<int>k, int ROOT){
if(sz(k) == 1){
if(k[0] == -1){
if(was == -1){
was = lst;
x[lst]=lst;
y[lst]=ROOT;
lst++;
}
return was;
}
return k[0];
}
// assert(sz(k) != 0);
vector<int>st[2];
if(sz(k) % 2 != 0)
k.insert(k.begin(), -1);
for(int i = 0; i < sz(k); ++i)
st[i&1].pb(k[i]);
// if(sz(st[0])>sz(st[1])){
// st[1].insert(st[1].begin(),-1);
// }
int v = lst++;
if(ROOT==-1){
ROOT = v;
}
int A=build(st[0],ROOT),B=build(st[1],ROOT);
x[v]=A;
y[v]=B;
return v;
}
int code(int f){
if(f <= m)
return f;
return -(f-m);
}
bool good(int f){
int pw=1;
int F = f;
while(f){
f>>=1;
pw<<=1;
}
pw>>=1;
if(pw==F)
return true;
return false;
}
void create_circuit(int M, std::vector<int> A){
for(int i=0;i<=M;++i)
trans[i].clear();
lst=0;
m = M;
A.push_back(0);
A.insert(A.begin(), 0);
for(int i = 0; i < sz(A) - 1; ++i){
trans[A[i]].push_back(A[i + 1]);
}
lst = M + 1;
vector < int > C(M + 1);
for(int i = 0; i <= M; ++i){
if(sz(trans[i]) == 0)
continue;
// reverse(all(trans[i]));
// while(!good(sz(trans[i]))){
// trans[i].pb(-1);
// }
// reverse(all(trans[i]));
// cout << " SZ " << sz(trans[i]) << endl;
was = -1;
if(sz(trans[i]) == 1){
C[i] = trans[i][0];
}else{
C[i] = code(build(trans[i], -1));
}
}
vector<int>X(lst-1-M),Y(lst-1-M);
for(int f=0;f<sz(X);++f){
X[f]=code(x[M+1+f]);
Y[f]=code(y[M+1+f]);
}
// cout << "WTF " << sz(X) << ' ' << N << endl;
assert(sz(X) <= 2 * sz(A));
// cout << "LOL \n";
// for(int i = 0; i <= M; ++i)
// cout << C[i] << '\n';
// for(int f = 0; f < sz(X); ++f){
// cout << X[f] << ' ' << Y[f] << endl;
// }
// cout << endl;
answer(C,X,Y);
}
/*
4 6
1 2 1 3 1 4
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
11980 KB |
Output is correct |
2 |
Correct |
29 ms |
15780 KB |
Output is correct |
3 |
Correct |
25 ms |
15428 KB |
Output is correct |
4 |
Correct |
6 ms |
11980 KB |
Output is correct |
5 |
Correct |
15 ms |
13132 KB |
Output is correct |
6 |
Correct |
33 ms |
17284 KB |
Output is correct |
7 |
Correct |
6 ms |
11980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
11980 KB |
Output is correct |
2 |
Correct |
29 ms |
15780 KB |
Output is correct |
3 |
Correct |
25 ms |
15428 KB |
Output is correct |
4 |
Correct |
6 ms |
11980 KB |
Output is correct |
5 |
Correct |
15 ms |
13132 KB |
Output is correct |
6 |
Correct |
33 ms |
17284 KB |
Output is correct |
7 |
Correct |
6 ms |
11980 KB |
Output is correct |
8 |
Correct |
52 ms |
18624 KB |
Output is correct |
9 |
Correct |
55 ms |
18928 KB |
Output is correct |
10 |
Correct |
81 ms |
22112 KB |
Output is correct |
11 |
Correct |
7 ms |
11980 KB |
Output is correct |
12 |
Correct |
6 ms |
11980 KB |
Output is correct |
13 |
Correct |
7 ms |
11980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
11980 KB |
Output is correct |
2 |
Correct |
29 ms |
15780 KB |
Output is correct |
3 |
Correct |
25 ms |
15428 KB |
Output is correct |
4 |
Correct |
6 ms |
11980 KB |
Output is correct |
5 |
Correct |
15 ms |
13132 KB |
Output is correct |
6 |
Correct |
33 ms |
17284 KB |
Output is correct |
7 |
Correct |
6 ms |
11980 KB |
Output is correct |
8 |
Correct |
52 ms |
18624 KB |
Output is correct |
9 |
Correct |
55 ms |
18928 KB |
Output is correct |
10 |
Correct |
81 ms |
22112 KB |
Output is correct |
11 |
Correct |
7 ms |
11980 KB |
Output is correct |
12 |
Correct |
6 ms |
11980 KB |
Output is correct |
13 |
Correct |
7 ms |
11980 KB |
Output is correct |
14 |
Incorrect |
118 ms |
24784 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
11980 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
8 ms |
11980 KB |
Output is partially correct |
2 |
Correct |
75 ms |
18792 KB |
Output is correct |
3 |
Partially correct |
123 ms |
24536 KB |
Output is partially correct |
4 |
Partially correct |
126 ms |
25108 KB |
Output is partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
8 ms |
11980 KB |
Output is partially correct |
2 |
Correct |
75 ms |
18792 KB |
Output is correct |
3 |
Partially correct |
123 ms |
24536 KB |
Output is partially correct |
4 |
Partially correct |
126 ms |
25108 KB |
Output is partially correct |
5 |
Partially correct |
136 ms |
26260 KB |
Output is partially correct |
6 |
Partially correct |
169 ms |
26964 KB |
Output is partially correct |
7 |
Partially correct |
151 ms |
26680 KB |
Output is partially correct |
8 |
Partially correct |
161 ms |
27412 KB |
Output is partially correct |
9 |
Partially correct |
114 ms |
22860 KB |
Output is partially correct |
10 |
Partially correct |
169 ms |
27548 KB |
Output is partially correct |
11 |
Partially correct |
164 ms |
27800 KB |
Output is partially correct |
12 |
Partially correct |
111 ms |
22432 KB |
Output is partially correct |
13 |
Partially correct |
98 ms |
21928 KB |
Output is partially correct |
14 |
Partially correct |
102 ms |
21596 KB |
Output is partially correct |
15 |
Partially correct |
128 ms |
21404 KB |
Output is partially correct |
16 |
Partially correct |
8 ms |
12348 KB |
Output is partially correct |
17 |
Partially correct |
88 ms |
20288 KB |
Output is partially correct |
18 |
Partially correct |
89 ms |
20228 KB |
Output is partially correct |
19 |
Partially correct |
99 ms |
20788 KB |
Output is partially correct |
20 |
Partially correct |
119 ms |
23592 KB |
Output is partially correct |
21 |
Partially correct |
147 ms |
25760 KB |
Output is partially correct |
22 |
Partially correct |
120 ms |
22804 KB |
Output is partially correct |