#include <bits/stdc++.h>
#include "doll.h"
using namespace std;
#define SIZE(x) (int)x.size()
#define forn(i,n) for(int i=0;i<int(n);i++)
#define forsn(i,s,n) for(int i=int(s);i<int(n);i++)
#define pb push_back
typedef vector<int> vi;
vi L, R, v, state;
int t=1, skip, s=-1;
void build(int u, int l, int r) {
L.pb(0), R.pb(0), v.pb(0);
if(r-l<=skip) {
v[u]=-1;
skip-=r-l;
return;
}
if(r-l==1) return;
v[u] = s--;
int m=(l+r)/2;
L[u] = t++;
build(L[u], l, m);
R[u] = t++;
build(R[u], m, r);
}
bool dfs(int u, int a) {
if(u && v[u]==-1) return false;
if(!v[u]) {
v[u]=a;
return true;
}
if(state[u]^=1) return dfs(L[u],a);
return dfs(R[u],a);
}
void create_circuit(int m, vi a) {
vi c(m+1,0), x, y;
c[0]=a[0];
int n=SIZE(a);
if(n==1) {
answer(c,x,y);
return;
}
forsn(i,1,m+1) c[i]=-1;
int sz=1;
while(sz<n) sz*=2;
skip = sz-n;
build(0,0,sz);
a.pb(0);
state.assign(SIZE(v),0);
forn(i,n) while(!dfs(0,a[i+1]));
forn(i,SIZE(v)) {
if(L[i] || R[i]) x.pb(v[L[i]]), y.pb(v[R[i]]);
}
answer(c,x,y);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
504 KB |
Output is correct |
2 |
Correct |
40 ms |
5808 KB |
Output is correct |
3 |
Correct |
33 ms |
6320 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
7 ms |
1444 KB |
Output is correct |
6 |
Correct |
56 ms |
8920 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
504 KB |
Output is correct |
2 |
Correct |
40 ms |
5808 KB |
Output is correct |
3 |
Correct |
33 ms |
6320 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
7 ms |
1444 KB |
Output is correct |
6 |
Correct |
56 ms |
8920 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
71 ms |
10504 KB |
Output is correct |
9 |
Correct |
70 ms |
11812 KB |
Output is correct |
10 |
Correct |
114 ms |
16068 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
504 KB |
Output is correct |
2 |
Correct |
40 ms |
5808 KB |
Output is correct |
3 |
Correct |
33 ms |
6320 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
7 ms |
1444 KB |
Output is correct |
6 |
Correct |
56 ms |
8920 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
71 ms |
10504 KB |
Output is correct |
9 |
Correct |
70 ms |
11812 KB |
Output is correct |
10 |
Correct |
114 ms |
16068 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
116 ms |
15476 KB |
Output is correct |
15 |
Correct |
65 ms |
10728 KB |
Output is correct |
16 |
Correct |
114 ms |
15764 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
111 ms |
15832 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
64 ms |
9652 KB |
Output is correct |
3 |
Correct |
62 ms |
10196 KB |
Output is correct |
4 |
Correct |
99 ms |
14476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
64 ms |
9652 KB |
Output is correct |
3 |
Correct |
62 ms |
10196 KB |
Output is correct |
4 |
Correct |
99 ms |
14476 KB |
Output is correct |
5 |
Correct |
108 ms |
15340 KB |
Output is correct |
6 |
Correct |
109 ms |
15320 KB |
Output is correct |
7 |
Correct |
104 ms |
15364 KB |
Output is correct |
8 |
Correct |
109 ms |
15212 KB |
Output is correct |
9 |
Correct |
60 ms |
10148 KB |
Output is correct |
10 |
Correct |
107 ms |
15276 KB |
Output is correct |
11 |
Correct |
102 ms |
14832 KB |
Output is correct |
12 |
Correct |
61 ms |
10264 KB |
Output is correct |
13 |
Correct |
67 ms |
10024 KB |
Output is correct |
14 |
Correct |
63 ms |
10780 KB |
Output is correct |
15 |
Correct |
73 ms |
10628 KB |
Output is correct |
16 |
Correct |
2 ms |
600 KB |
Output is correct |
17 |
Correct |
66 ms |
9824 KB |
Output is correct |
18 |
Correct |
67 ms |
9652 KB |
Output is correct |
19 |
Correct |
65 ms |
10400 KB |
Output is correct |
20 |
Correct |
113 ms |
15180 KB |
Output is correct |
21 |
Correct |
103 ms |
14852 KB |
Output is correct |
22 |
Correct |
99 ms |
14988 KB |
Output is correct |