#include <bits/stdc++.h>
using namespace std;
int A,B,C,S;
set<pair<int,int>> s;
int a,b,c;
struct maciek{int x; int y; int l;};
queue<maciek>kolejka;
maciek make_maciek(int d,int e, int f)
{
maciek X;
X.x=d;
X.y=e;
X.l=f;
return X;
}
int AD[100100];
void wstaw(maciek Y)
{
int aa=Y.x;
int bb=Y.y;
int cc=S-aa-bb;
if(AD[aa]==-1)AD[aa]=Y.l;
if(AD[bb]==-1)AD[bb]=Y.l;
if(AD[cc]==-1)AD[cc]=Y.l;
if(aa+bb<=B)
{
if(s.find(make_pair(0,aa+bb))==s.end())
{
kolejka.push(make_maciek(0,aa+bb,Y.l+1));
s.insert(make_pair(0,aa+bb));
}
}
else
{
if(s.find(make_pair(aa+bb-B,B))==s.end())
{
kolejka.push(make_maciek(aa+bb-B,B,Y.l+1));
s.insert(make_pair(aa+bb-B,B));
}
}
if(aa+bb<=A)
{
if(s.find(make_pair(aa+bb,0))==s.end())
{
kolejka.push(make_maciek(aa+bb,0,Y.l+1));
s.insert(make_pair(aa+bb,0));
}
}
else
{
if(s.find(make_pair(A,aa+bb-A))==s.end())
{
kolejka.push(make_maciek(A,aa+bb-A,Y.l+1));
s.insert(make_pair(A,aa+bb-A));
}
}
if(aa+cc<=C)
{
if(s.find(make_pair(0,bb))==s.end())
{
kolejka.push(make_maciek(0,bb,Y.l+1));
s.insert(make_pair(0,bb));
}
}
else
{
if(s.find(make_pair(aa+cc-C,bb))==s.end())
{
kolejka.push(make_maciek(aa+cc-C,bb,Y.l+1));
s.insert(make_pair(aa+cc-C,bb));
}
}
if(aa+cc<=A)
{
if(s.find(make_pair(aa+cc,bb))==s.end())
{
kolejka.push(make_maciek(aa+cc,bb,Y.l+1));
s.insert(make_pair(aa+cc,bb));
}
}
else
{
if(s.find(make_pair(A,bb))==s.end())
{
kolejka.push(make_maciek(A,bb,Y.l+1));
s.insert(make_pair(A,bb));
}
}
if(cc+bb<=B)
{
if(s.find(make_pair(aa,cc+bb))==s.end())
{
kolejka.push(make_maciek(aa,bb+cc,Y.l+1));
s.insert(make_pair(aa,bb+cc));
}
}
else
{
if(s.find(make_pair(aa,B))==s.end())
{
kolejka.push(make_maciek(aa,B,Y.l+1));
s.insert(make_pair(aa,B));
}
}
if(cc+bb<=C)
{
if(s.find(make_pair(aa,0))==s.end())
{
kolejka.push(make_maciek(aa,0,Y.l+1));
s.insert(make_pair(aa,0));
}
}
else
{
if(s.find(make_pair(aa,bb+cc-C))==s.end())
{
kolejka.push(make_maciek(aa,bb+cc-C,Y.l+1));
s.insert(make_pair(aa,bb+cc-C));
}
}
}
void BFS()
{
while(kolejka.size()!=0)
{
maciek Y=kolejka.front();
kolejka.pop();
wstaw(Y);
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin>>A>>B>>C;
cin>>a>>b>>c;
S=a+b+c;
kolejka.push(make_maciek(a,b,0));
s.insert(make_pair(a,b));
for(int i=0;i<=C;i++)
{
AD[i]=-1;
}
BFS();
for(int i=0;i<=C;i++)
{
cout<<AD[i]<<" ";
}
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | #include <bits/stdc++.h> using namespace std; int A,B,C,S; set<pair<int,int>> s; int a,b,c; struct maciek{int x; int y; int l;}; queue<maciek>kolejka; maciek make_maciek(int d,int e, int f) { maciek X; X.x=d; X.y=e; X.l=f; return X; } int AD[100100]; void wstaw(maciek Y) { int aa=Y.x; int bb=Y.y; int cc=S-aa-bb; if(AD[aa]==-1)AD[aa]=Y.l; if(AD[bb]==-1)AD[bb]=Y.l; if(AD[cc]==-1)AD[cc]=Y.l; if(aa+bb<=B) { if(s.find(make_pair(0,aa+bb))==s.end()) { kolejka.push(make_maciek(0,aa+bb,Y.l+1)); s.insert(make_pair(0,aa+bb)); } } else { if(s.find(make_pair(aa+bb-B,B))==s.end()) { kolejka.push(make_maciek(aa+bb-B,B,Y.l+1)); s.insert(make_pair(aa+bb-B,B)); } } if(aa+bb<=A) { if(s.find(make_pair(aa+bb,0))==s.end()) { kolejka.push(make_maciek(aa+bb,0,Y.l+1)); s.insert(make_pair(aa+bb,0)); } } else { if(s.find(make_pair(A,aa+bb-A))==s.end()) { kolejka.push(make_maciek(A,aa+bb-A,Y.l+1)); s.insert(make_pair(A,aa+bb-A)); } } if(aa+cc<=C) { if(s.find(make_pair(0,bb))==s.end()) { kolejka.push(make_maciek(0,bb,Y.l+1)); s.insert(make_pair(0,bb)); } } else { if(s.find(make_pair(aa+cc-C,bb))==s.end()) { kolejka.push(make_maciek(aa+cc-C,bb,Y.l+1)); s.insert(make_pair(aa+cc-C,bb)); } } if(aa+cc<=A) { if(s.find(make_pair(aa+cc,bb))==s.end()) { kolejka.push(make_maciek(aa+cc,bb,Y.l+1)); s.insert(make_pair(aa+cc,bb)); } } else { if(s.find(make_pair(A,bb))==s.end()) { kolejka.push(make_maciek(A,bb,Y.l+1)); s.insert(make_pair(A,bb)); } } if(cc+bb<=B) { if(s.find(make_pair(aa,cc+bb))==s.end()) { kolejka.push(make_maciek(aa,bb+cc,Y.l+1)); s.insert(make_pair(aa,bb+cc)); } } else { if(s.find(make_pair(aa,B))==s.end()) { kolejka.push(make_maciek(aa,B,Y.l+1)); s.insert(make_pair(aa,B)); } } if(cc+bb<=C) { if(s.find(make_pair(aa,0))==s.end()) { kolejka.push(make_maciek(aa,0,Y.l+1)); s.insert(make_pair(aa,0)); } } else { if(s.find(make_pair(aa,bb+cc-C))==s.end()) { kolejka.push(make_maciek(aa,bb+cc-C,Y.l+1)); s.insert(make_pair(aa,bb+cc-C)); } } } void BFS() { while(kolejka.size()!=0) { maciek Y=kolejka.front(); kolejka.pop(); wstaw(Y); } } int main() { ios_base::sync_with_stdio(0); cin>>A>>B>>C; cin>>a>>b>>c; S=a+b+c; kolejka.push(make_maciek(a,b,0)); s.insert(make_pair(a,b)); for(int i=0;i<=C;i++) { AD[i]=-1; } BFS(); for(int i=0;i<=C;i++) { cout<<AD[i]<<" "; } } |
English