#include <bits/stdc++.h>
#define ll long long
#define db long double
#define maxn 1000005
#define II pair <ll,ll>
#define III pair <ll,II>
#define IV pair <vector <int>,vector <int> >
#define IDB pair <db,int>
#define TII pair <treap*,treap*>
#define fst first
#define snd second
#define BIT(x,i) ((x>>i)&1)
#define pi acos(-1)
#define to_radian(x) (x*pi/180.0)
#define to_degree(x) (x*180.0/pi)
#define Log(x) (31-__builtin_clz((int)x))
#define LogLL(x) (63-__builtin_clzll((ll)x)
#include "doll.h"
using namespace std;
int s,i,n,m,numa[maxn],numb[maxn],k,num[maxn],a[maxn];
vector <int> res,X,Y,to[maxn],Status;
/*
void answer(vector <int> res,vector <int> X,vector <int> Y)
{
for(int x:res) cout<<x<<'\n';
for(int i=0;i<s;i++) cout<<X[i]<<" "<<Y[i]<<'\n';
}*/
struct Graph
{
int n=0;
vector <int> X,Y;
vector <II> sink;
};
Graph cal(int n)
{
Graph res;
if(n==2)
{
res.n=1;
res.X.push_back(0); res.X.push_back(-1);
res.Y.push_back(0); res.Y.push_back(-1);
res.sink.push_back({ 1,0 });
res.sink.push_back({ 1,1 });
return res;
}
res.n=1;
Graph a=cal(n/2),b=a;
res.X.resize(a.n+b.n+2);
res.Y.resize(a.n+b.n+2);
res.X[1]=res.n+1;
for(int i=1;i<=a.n;i++) numa[i]=++res.n;
for(int i=1;i<=a.n;i++)
{
res.X[numa[i]]=(a.X[i]>-1 ? numa[a.X[i]] : -1);
res.Y[numa[i]]=(a.Y[i]>-1 ? numa[a.Y[i]] : -1);
}
res.Y[1]=res.n+1;
for(int i=1;i<=b.n;i++) numb[i]=++res.n;
for(int i=1;i<=b.n;i++)
{
res.X[numb[i]]=(b.X[i]>-1 ? numb[b.X[i]] : -1);
res.Y[numb[i]]=(b.Y[i]>-1 ? numb[b.Y[i]] : -1);
}
for(int i=0;i<a.sink.size();i++)
{
res.sink.push_back({ numa[a.sink[i].fst],a.sink[i].snd });
res.sink.push_back({ numb[b.sink[i].fst],b.sink[i].snd });
}
return res;
}
Graph Contructive(int mask,int high)
{
Graph res;
if(high==0)
{
res.n=1;
res.X.push_back(0);
if(BIT(mask,high)) res.X.push_back(-1); else res.X.push_back(-2);
res.Y.push_back(0); res.Y.push_back(-1);
return res;
}
res.n=1;
if(BIT(mask,high))
{
Graph a=cal(1<<high),b=Contructive(mask^(1<<high),high-1);
res.X.resize(a.n+b.n+2);
res.Y.resize(a.n+b.n+2);
res.X[1]=res.n+1;
for(int i=1;i<=a.n;i++) numa[i]=++res.n;
for(int i=1;i<=a.n;i++)
{
res.X[numa[i]]=(a.X[i]>-1 ? numa[a.X[i]] : a.X[i]);
res.Y[numa[i]]=(a.Y[i]>-1 ? numa[a.Y[i]] : a.Y[i]);
}
res.Y[1]=res.n+1;
for(int i=1;i<=b.n;i++) numb[i]=++res.n;
for(int i=1;i<=b.n;i++)
{
res.X[numb[i]]=(b.X[i]>-1 ? numb[b.X[i]] : b.X[i]);
res.Y[numb[i]]=(b.Y[i]>-1 ? numb[b.Y[i]] : b.Y[i]);
}
}
else
{
Graph b=Contructive(mask,high-1);
res.X.resize(b.n+2);
res.Y.resize(b.n+2);
res.X[1]=-2;
res.Y[1]=res.n+1;
for(int i=1;i<=b.n;i++) numb[i]=++res.n;
for(int i=1;i<=b.n;i++)
{
res.X[numb[i]]=(b.X[i]>-1 ? numb[b.X[i]] : b.X[i]);
res.Y[numb[i]]=(b.Y[i]>-1 ? numb[b.Y[i]] : b.Y[i]);
}
}
return res;
}
void sub_full()
{
res.resize(m+1);
res[0]=a[1];
if(n==1)
{
res[a[1]]=0;
return ;
}
Graph G=Contructive(n-1,Log(n-1));
for(i=1;i<=m;i++) res[i]=-1;
for(i=1;i<=G.n;i++) num[i]=++s;
X.resize(s);
Y.resize(s);
Status.resize(s);
for(i=1;i<=G.n;i++)
{
X[num[i]-1]=(G.X[i]>0 ? -num[G.X[i]] : 1e9*G.X[i]);
Y[num[i]-1]=(G.Y[i]>0 ? -num[G.Y[i]] : 1e9*G.Y[i]);
}
int u=1,idx=1;
while(u!=0)
if(u>0) u=-1;
else
{
// cerr<<u<<" "<<idx<<'\n';
int i=-u-1;
if(Status[i]==0)
{
if(X[i]==-1e9) X[i]=a[++idx];
if(X[i]==-2e9) X[i]=-1;
u=X[i];
}
else
{
if(Y[i]==-1e9) Y[i]=a[++idx];
if(Y[i]==-2e9) Y[i]=-1;
u=Y[i];
}
Status[i]^=1;
}
}
void create_circuit(int _m,vector <int> _a)
{
m=_m; n=_a.size();
int ok=1;
for(i=0;i<n;i++)
{
a[i+1]=_a[i];
if(i+1<n) to[_a[i]].push_back(_a[i+1]);
else to[_a[i]].push_back(0);
}
for(i=1;i<=m;i++)
ok&=(to[i].size()<=4);
sub_full();
answer(res,X,Y);
}
/*
int main()
{
freopen("doll.inp","r",stdin);
freopen("doll.out","w",stdout);
int m,n,k;
cin>>m;
vector <int> a;
while(cin>>k) a.push_back(k);
create_circuit(m,a);
}
*/
Compilation message
doll.cpp: In function 'Graph cal(int)':
doll.cpp:64:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
64 | for(int i=0;i<a.sink.size();i++)
| ~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
33368 KB |
Output is correct |
2 |
Correct |
47 ms |
40392 KB |
Output is correct |
3 |
Correct |
46 ms |
39668 KB |
Output is correct |
4 |
Correct |
8 ms |
33368 KB |
Output is correct |
5 |
Correct |
14 ms |
34516 KB |
Output is correct |
6 |
Correct |
66 ms |
43736 KB |
Output is correct |
7 |
Correct |
6 ms |
27228 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
33368 KB |
Output is correct |
2 |
Correct |
47 ms |
40392 KB |
Output is correct |
3 |
Correct |
46 ms |
39668 KB |
Output is correct |
4 |
Correct |
8 ms |
33368 KB |
Output is correct |
5 |
Correct |
14 ms |
34516 KB |
Output is correct |
6 |
Correct |
66 ms |
43736 KB |
Output is correct |
7 |
Correct |
6 ms |
27228 KB |
Output is correct |
8 |
Correct |
76 ms |
43120 KB |
Output is correct |
9 |
Correct |
84 ms |
44212 KB |
Output is correct |
10 |
Correct |
118 ms |
48440 KB |
Output is correct |
11 |
Correct |
7 ms |
33368 KB |
Output is correct |
12 |
Correct |
7 ms |
33372 KB |
Output is correct |
13 |
Correct |
7 ms |
29316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
33368 KB |
Output is correct |
2 |
Correct |
47 ms |
40392 KB |
Output is correct |
3 |
Correct |
46 ms |
39668 KB |
Output is correct |
4 |
Correct |
8 ms |
33368 KB |
Output is correct |
5 |
Correct |
14 ms |
34516 KB |
Output is correct |
6 |
Correct |
66 ms |
43736 KB |
Output is correct |
7 |
Correct |
6 ms |
27228 KB |
Output is correct |
8 |
Correct |
76 ms |
43120 KB |
Output is correct |
9 |
Correct |
84 ms |
44212 KB |
Output is correct |
10 |
Correct |
118 ms |
48440 KB |
Output is correct |
11 |
Correct |
7 ms |
33368 KB |
Output is correct |
12 |
Correct |
7 ms |
33372 KB |
Output is correct |
13 |
Correct |
7 ms |
29316 KB |
Output is correct |
14 |
Correct |
110 ms |
46724 KB |
Output is correct |
15 |
Correct |
98 ms |
41436 KB |
Output is correct |
16 |
Correct |
123 ms |
46300 KB |
Output is correct |
17 |
Correct |
9 ms |
33368 KB |
Output is correct |
18 |
Correct |
7 ms |
33372 KB |
Output is correct |
19 |
Correct |
7 ms |
33372 KB |
Output is correct |
20 |
Correct |
120 ms |
47556 KB |
Output is correct |
21 |
Correct |
7 ms |
33368 KB |
Output is correct |
22 |
Correct |
7 ms |
33376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
33372 KB |
Output is correct |
2 |
Correct |
6 ms |
33412 KB |
Output is correct |
3 |
Correct |
7 ms |
33372 KB |
Output is correct |
4 |
Correct |
6 ms |
33372 KB |
Output is correct |
5 |
Correct |
6 ms |
33372 KB |
Output is correct |
6 |
Correct |
7 ms |
33372 KB |
Output is correct |
7 |
Correct |
8 ms |
33372 KB |
Output is correct |
8 |
Correct |
8 ms |
33372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
33408 KB |
Output is correct |
2 |
Correct |
64 ms |
40140 KB |
Output is correct |
3 |
Correct |
65 ms |
40844 KB |
Output is correct |
4 |
Correct |
97 ms |
44212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
33408 KB |
Output is correct |
2 |
Correct |
64 ms |
40140 KB |
Output is correct |
3 |
Correct |
65 ms |
40844 KB |
Output is correct |
4 |
Correct |
97 ms |
44212 KB |
Output is correct |
5 |
Correct |
115 ms |
46816 KB |
Output is correct |
6 |
Correct |
115 ms |
46396 KB |
Output is correct |
7 |
Correct |
118 ms |
46544 KB |
Output is correct |
8 |
Correct |
106 ms |
46116 KB |
Output is correct |
9 |
Correct |
65 ms |
40988 KB |
Output is correct |
10 |
Correct |
107 ms |
45224 KB |
Output is correct |
11 |
Correct |
95 ms |
45748 KB |
Output is correct |
12 |
Correct |
64 ms |
40924 KB |
Output is correct |
13 |
Correct |
82 ms |
42000 KB |
Output is correct |
14 |
Correct |
72 ms |
41720 KB |
Output is correct |
15 |
Correct |
74 ms |
41928 KB |
Output is correct |
16 |
Correct |
8 ms |
33612 KB |
Output is correct |
17 |
Correct |
64 ms |
40932 KB |
Output is correct |
18 |
Correct |
63 ms |
41136 KB |
Output is correct |
19 |
Correct |
64 ms |
40644 KB |
Output is correct |
20 |
Correct |
120 ms |
45400 KB |
Output is correct |
21 |
Correct |
112 ms |
44704 KB |
Output is correct |
22 |
Correct |
96 ms |
45128 KB |
Output is correct |