#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define nd second
#define st first
#define mp make_pair
int A, B, C;
queue<pair < pair<int, int>, pair<int, int> > >kol;
map<pair<pair<int,int>, int>, bool> mapa;
int tab[100009];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int a, b, c, d, e, f, czas;
cin>>A>>B>>C>>a>>b>>c;
fill(tab, tab+100007, 10000009);
kol.push(mp(mp(0, a), mp(b, c)));
while(!kol.empty())
{
czas=kol.front().st.st;
d=kol.front().st.nd;
e=kol.front().nd.st;
f=kol.front().nd.nd;
// cout<<"wchodze dla e = "<<d<<" e = "<<e<<" f = "<<f<<" czas = "<<czas<<"\n";
kol.pop();
if( mapa.count(mp(mp(d, e), f))) continue;
mapa[mp(mp(d, e), f)]=1;
if(tab[d]>czas) tab[d]=czas;
if(tab[e]>czas) tab[e]=czas;
if(tab[f]>czas) tab[f]=czas;
kol.push( mp( mp(czas+1, d-min(B-e, d)), mp(e+min(B-e, d), f) ));
kol.push( mp( mp(czas+1, d+min(A-d, e)), mp(e-min(A-d, e), f) ));
kol.push( mp( mp(czas+1, d-min(C-f, d)), mp(e, f+min(C-f, d)) ));
kol.push( mp( mp(czas+1, d+min(A-d, f)), mp(e, f-min(A-d, f)) ));
kol.push( mp( mp(czas+1, d), mp(e-min(C-f, e), f+min(C-f, e)) ));
kol.push( mp( mp(czas+1, d), mp(e+min(B-e, f), f-min(B-e, f)) ));
}
for(int i=0;i<=C;i++)
{
if(tab[i]>100050)
{
cout<<-1<<" ";
continue;
}
cout<<tab[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 | #include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define nd second #define st first #define mp make_pair int A, B, C; queue<pair < pair<int, int>, pair<int, int> > >kol; map<pair<pair<int,int>, int>, bool> mapa; int tab[100009]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int a, b, c, d, e, f, czas; cin>>A>>B>>C>>a>>b>>c; fill(tab, tab+100007, 10000009); kol.push(mp(mp(0, a), mp(b, c))); while(!kol.empty()) { czas=kol.front().st.st; d=kol.front().st.nd; e=kol.front().nd.st; f=kol.front().nd.nd; // cout<<"wchodze dla e = "<<d<<" e = "<<e<<" f = "<<f<<" czas = "<<czas<<"\n"; kol.pop(); if( mapa.count(mp(mp(d, e), f))) continue; mapa[mp(mp(d, e), f)]=1; if(tab[d]>czas) tab[d]=czas; if(tab[e]>czas) tab[e]=czas; if(tab[f]>czas) tab[f]=czas; kol.push( mp( mp(czas+1, d-min(B-e, d)), mp(e+min(B-e, d), f) )); kol.push( mp( mp(czas+1, d+min(A-d, e)), mp(e-min(A-d, e), f) )); kol.push( mp( mp(czas+1, d-min(C-f, d)), mp(e, f+min(C-f, d)) )); kol.push( mp( mp(czas+1, d+min(A-d, f)), mp(e, f-min(A-d, f)) )); kol.push( mp( mp(czas+1, d), mp(e-min(C-f, e), f+min(C-f, e)) )); kol.push( mp( mp(czas+1, d), mp(e+min(B-e, f), f-min(B-e, f)) )); } for(int i=0;i<=C;i++) { if(tab[i]>100050) { cout<<-1<<" "; continue; } cout<<tab[i]<<" "; } } |
English