#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];
vector <int> res,X,Y,to[maxn];
/*
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+1)/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++)
{
// cerr<<i<<" "<<a.X.size()<<" "<<numa[i]<<" "<<res.X.size()<<'\n';
res.X[numa[i]]=numa[a.X[i]];
// cerr<<i<<" "<<a.X.size()<<" "<<numa[i]<<" "<<X.size()<<'\n';
res.Y[numa[i]]=numa[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]]=numb[b.X[i]];
res.Y[numb[i]]=numb[b.Y[i]];
}
if(n&1)
{
if(b.sink[b.sink.size()-2].snd==0)
res.X[numb[b.sink[b.sink.size()-2].fst]]=1;
else res.Y[numb[b.sink[b.sink.size()-2].fst]]=1;
for(int i=0;i<a.sink.size()-2;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 });
}
res.sink.push_back({ numa[a.sink[a.sink.size()-2].fst],a.sink[a.sink.size()-2].snd });
res.sink.push_back({ numa[a.sink[a.sink.size()-1].fst],a.sink[a.sink.size()-1].snd });
res.sink.push_back({ numb[b.sink[b.sink.size()-1].fst],b.sink[b.sink.size()-1].snd });
}
else
{
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;
}
void sub1()
{
for(k=1;k<=m;k++)
{
if(to[k].size()==1)
{
res[k-1]=to[k].back();
continue;
}
if(to[k].size()==0)
{
res[k-1]=0;
continue;
}
Graph G=cal(to[k].size());
res[k-1]=-s-1;
for(i=1;i<=G.n;i++) num[i]=++s;
for(i=1;i<=G.n;i++)
{
X[num[i]-1]=-num[G.X[i]];
Y[num[i]-1]=-num[G.Y[i]];
}
for(i=0;i<to[k].size();i++)
{
if(G.sink[i].snd==0)
X[num[G.sink[i].fst]-1]=to[k][i];
else Y[num[G.sink[i].fst]-1]=to[k][i];
}
}
while(X.size()>s) X.pop_back();
while(Y.size()>s) Y.pop_back();
answer(res,X,Y);
}
void create_circuit(int _m,vector <int> a)
{
m=_m; n=a.size();
int ok=1;
for(i=0;i<n;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);
res.resize(m);
X.resize(2*n); Y.resize(2*n);
if(ok) sub1();
}
/*
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:72:22: 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]
72 | for(int i=0;i<a.sink.size()-2;i++)
| ~^~~~~~~~~~~~~~~~
doll.cpp:83:22: 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]
83 | for(int i=0;i<a.sink.size();i++)
| ~^~~~~~~~~~~~~~
doll.cpp: In function 'void sub1()':
doll.cpp:113:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
113 | for(i=0;i<to[k].size();i++)
| ~^~~~~~~~~~~~~
doll.cpp:120:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
120 | while(X.size()>s) X.pop_back();
| ~~~~~~~~^~
doll.cpp:121:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
121 | while(Y.size()>s) Y.pop_back();
| ~~~~~~~~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
27228 KB |
Wrong Answer: wrong array length |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
27228 KB |
Wrong Answer: wrong array length |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
27228 KB |
Wrong Answer: wrong array length |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
25180 KB |
Wrong Answer: answered not exactly once |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
25180 KB |
Wrong Answer: answered not exactly once |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
25180 KB |
Wrong Answer: answered not exactly once |
2 |
Halted |
0 ms |
0 KB |
- |