#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=0;
void build(int u, int l, int r) { //[l,r]
L.pb(0), R.pb(0), v.pb(1);
if(l>r) return;
if(skip>0 && r-l+1<=skip) {
assert(u>=0);
assert(u<SIZE(v));
v[u]=-1;
skip-=r-l+1;
return;
}
if(l==r) {
assert(u>=0);
assert(u<SIZE(v));
v[u]=0;
return;
}
v[u]=--s;
int m=(l+r)/2;
assert(u>=0);
assert(u<SIZE(L));
L[u] = t++;
build(L[u], l, m);
assert(u>=0);
assert(u<SIZE(R));
R[u] = t++;
build(R[u], m+1, r);
//dbgm(u,l,r,v[u],L[u],R[u]);
}
bool dfs(int u, int a) {
//dbg(u);
assert(u>=0);
assert(u<SIZE(v));
if(u!=0 && v[u]==-1) return false;
if(!v[u]) {
//dbgm(u,v[u]);
v[u]=a;
return true;
}
assert(u<SIZE(state));
state[u]^=1;
assert(u<SIZE(L));
assert(u<SIZE(R));
assert(v[L[u]]!=-1 || v[R[u]]!=-1);
if(state[u]) return dfs(L[u],a);
return dfs(R[u],a);
}
void create_circuit(int m, vi A) {
vi c(m+1);
assert(0<SIZE(c));
assert(0<SIZE(A));
c[0]=A[0];
forsn(i,1,m+1) {
assert(i>=0);
assert(i<SIZE(c));
c[i]=-1;
}
int n=SIZE(A);
int sz=1;
while(sz<n) sz*=2;
assert(sz>=n);
skip = sz-n;
build(0,1,sz);
assert(SIZE(L)==SIZE(R));
assert(SIZE(v)==SIZE(L));
//dbgm(L,R,v);
vi a;
forsn(i,1,n) {
assert(i>=0);
assert(i<SIZE(A));
a.pb(A[i]);
}
a.pb(0);
assert(SIZE(a)==n);
state.assign(SIZE(v),0);
forn(i,n) {
assert(i<SIZE(a));
bool flag=0;
while(!flag) flag=dfs(0,a[i]);
}
vi x, y;
forn(i,SIZE(v)) {
assert(i<SIZE(L));
assert(i<SIZE(R));
if(L[i] && R[i]) {
x.pb(v[L[i]]);
y.pb(v[R[i]]);
}
}
answer(c,x,y);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
39 ms |
6880 KB |
Output is correct |
3 |
Correct |
35 ms |
6580 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
7 ms |
1372 KB |
Output is correct |
6 |
Correct |
56 ms |
9944 KB |
Output is correct |
7 |
Incorrect |
1 ms |
348 KB |
wrong serial number |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
39 ms |
6880 KB |
Output is correct |
3 |
Correct |
35 ms |
6580 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
7 ms |
1372 KB |
Output is correct |
6 |
Correct |
56 ms |
9944 KB |
Output is correct |
7 |
Incorrect |
1 ms |
348 KB |
wrong serial number |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
39 ms |
6880 KB |
Output is correct |
3 |
Correct |
35 ms |
6580 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
7 ms |
1372 KB |
Output is correct |
6 |
Correct |
56 ms |
9944 KB |
Output is correct |
7 |
Incorrect |
1 ms |
348 KB |
wrong serial number |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
66 ms |
10444 KB |
Output is correct |
3 |
Correct |
71 ms |
10772 KB |
Output is correct |
4 |
Correct |
118 ms |
15528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
66 ms |
10444 KB |
Output is correct |
3 |
Correct |
71 ms |
10772 KB |
Output is correct |
4 |
Correct |
118 ms |
15528 KB |
Output is correct |
5 |
Correct |
124 ms |
16396 KB |
Output is correct |
6 |
Correct |
118 ms |
16548 KB |
Output is correct |
7 |
Correct |
145 ms |
16408 KB |
Output is correct |
8 |
Correct |
99 ms |
16256 KB |
Output is correct |
9 |
Correct |
62 ms |
10660 KB |
Output is correct |
10 |
Correct |
103 ms |
16148 KB |
Output is correct |
11 |
Correct |
126 ms |
15956 KB |
Output is correct |
12 |
Correct |
62 ms |
10916 KB |
Output is correct |
13 |
Correct |
67 ms |
11012 KB |
Output is correct |
14 |
Correct |
64 ms |
11292 KB |
Output is correct |
15 |
Correct |
64 ms |
11460 KB |
Output is correct |
16 |
Correct |
3 ms |
600 KB |
Output is correct |
17 |
Correct |
63 ms |
10680 KB |
Output is correct |
18 |
Correct |
63 ms |
10680 KB |
Output is correct |
19 |
Correct |
62 ms |
10964 KB |
Output is correct |
20 |
Correct |
99 ms |
15972 KB |
Output is correct |
21 |
Correct |
148 ms |
15956 KB |
Output is correct |
22 |
Correct |
104 ms |
15768 KB |
Output is correct |