#include<bits/stdc++.h>
using namespace std;
int a,b,c;
int odp[1000005];
queue< pair< pair<int,pair<int,int> > ,int >> q;
map < pair<int, pair<int,int> >, int > M;
void dodaj(int x,int y,int z,int w);
void oznacz(int x,int y,int z,int ite);
int main()
{
int x,y,z;
cin >> a >> b >> c;
cin >> x >> y >> z;
for(int i = 0 ; i <= c ; i++)
odp[i] = c * 100;;
oznacz(x,y,z,1);
for (auto i : M)
{
x = i.first.first;
y = i.first.second.first;
z = i.first.second.second;
int w = i.second;
//cout << x <<" " << y<<" " << z<<": " << w<<"\n";
odp[x] = min(odp[x],w-1);
odp[y] = min(odp[y],w-1);
odp[z] = min(odp[z],w-1);
}
for(int i = 0 ; i <= c ; i++)
{
if(odp[i] == c * 100)
cout << -1<<" ";
else
cout <<odp[i]<<" ";
}
}
void oznacz(int x,int y,int z,int ite)
{
dodaj(x,y,z,ite);
while(!q.empty())
{
pair< pair<int,pair<int,int> > ,int > elo = q.front();
q.pop();
x = elo.first.first;
y = elo.first.second.first;
z = elo.first.second.second;
ite = elo.second;
if(M[{x,{y,z}}] > ite || M[{x,{y,z}}] == 0)
{
M[{x,{y,z}}] = ite;
if(x + y > b)
dodaj(x + y - b,b,z,ite + 1);
else
dodaj(0,x+y,z,ite+1);
if(x + z > c)
dodaj(x+z-c,y,c,ite+1);
else
dodaj(0,y,z+x,ite+1);
if(y+x > a)
dodaj(a,x+y-a,z,ite+1);
else
dodaj(x+y,0,z,ite+1);
if(y+z > c)
dodaj(x,y+z-c,c,ite+1);
else
dodaj(x,0,y+z,ite+1);
if(z+x > a)
dodaj(a,y,z+x-a,ite+1);
else
dodaj(x+z,y,0,ite+1);
if(z+y > b)
dodaj(x,b,z+y-b,ite+1);
else
dodaj(x,y+z,0,ite+1);
}
}
}
void dodaj(int x,int y,int z,int w)
{
q.push({{x,{y,z}},w});
}
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 | #include<bits/stdc++.h> using namespace std; int a,b,c; int odp[1000005]; queue< pair< pair<int,pair<int,int> > ,int >> q; map < pair<int, pair<int,int> >, int > M; void dodaj(int x,int y,int z,int w); void oznacz(int x,int y,int z,int ite); int main() { int x,y,z; cin >> a >> b >> c; cin >> x >> y >> z; for(int i = 0 ; i <= c ; i++) odp[i] = c * 100;; oznacz(x,y,z,1); for (auto i : M) { x = i.first.first; y = i.first.second.first; z = i.first.second.second; int w = i.second; //cout << x <<" " << y<<" " << z<<": " << w<<"\n"; odp[x] = min(odp[x],w-1); odp[y] = min(odp[y],w-1); odp[z] = min(odp[z],w-1); } for(int i = 0 ; i <= c ; i++) { if(odp[i] == c * 100) cout << -1<<" "; else cout <<odp[i]<<" "; } } void oznacz(int x,int y,int z,int ite) { dodaj(x,y,z,ite); while(!q.empty()) { pair< pair<int,pair<int,int> > ,int > elo = q.front(); q.pop(); x = elo.first.first; y = elo.first.second.first; z = elo.first.second.second; ite = elo.second; if(M[{x,{y,z}}] > ite || M[{x,{y,z}}] == 0) { M[{x,{y,z}}] = ite; if(x + y > b) dodaj(x + y - b,b,z,ite + 1); else dodaj(0,x+y,z,ite+1); if(x + z > c) dodaj(x+z-c,y,c,ite+1); else dodaj(0,y,z+x,ite+1); if(y+x > a) dodaj(a,x+y-a,z,ite+1); else dodaj(x+y,0,z,ite+1); if(y+z > c) dodaj(x,y+z-c,c,ite+1); else dodaj(x,0,y+z,ite+1); if(z+x > a) dodaj(a,y,z+x-a,ite+1); else dodaj(x+z,y,0,ite+1); if(z+y > b) dodaj(x,b,z+y-b,ite+1); else dodaj(x,y+z,0,ite+1); } } } void dodaj(int x,int y,int z,int w) { q.push({{x,{y,z}},w}); } |
English