#include<bits/stdc++.h> using namespace std; int A,B,C,a,b,c,tab[100007]; #define inf 10000000 void but(int n,int p,int a1,int b1, int c1,int it) { it++; if(it>C*2) return; if(n==1) { if(p!=2) { int il=min(a1,B-b1); if(il) { tab[a1-il]=min(tab[a1-il],it); tab[b1+il]=min(tab[b1+il],it); int ll=min(b1+il,C-c1); if(tab[b1+il-ll]>=it || tab[c1+ll]>=it) but(2,1,a1-il,b1+il,c1,it); ll=min(a1-il,C-c1); if(tab[a1-il-ll]>=it || tab[c1+ll]>=it) but(1,2,a1-il,b1+il,c1,it); but(3,0,a1-il,b1+il,c1,it); } } if(p!=3) { int il=min(a1,C-c1); if(il) { tab[a1-il]=min(tab[a1-il],it); tab[c1+il]=min(tab[c1+il],it); int ll=min(c1+il,B-b1); if(tab[c1+il-ll]>=it || tab[b1+ll]>=it) but(3,1,a1-il,b1,c1+il,it); ll=min(a1-il,B-b1); if(tab[a1-il-ll]>=it || tab[b1+ll]>=it) but(1,3,a1-il,b1,c1+il,it); but(2,0,a1-il,b1,c1+il,it); } } return ; } if(n==2) { if(p!=1) { int il=min(b1,A-a1); if(il) { tab[b1-il]=min(tab[b1-il],it); tab[a1+il]=min(tab[a1+il],it); int ll=min(a1+il,C-c1); if(tab[a1+il-ll]>=it || tab[c1+ll]>=it) but(1,2,a1+il,b1-il,c1,it); ll=min(b1-il,C-c1); if(tab[b1-il-ll]>=it || tab[c1+ll]>=it) but(2,1,a1+il,b1-il,c1,it); but(3,0,a1+il,b1-il,c1,it); } } if(p!=3) { int il=min(b1,C-c1); if(il) { tab[b1-il]=min(tab[b1-il],it); tab[c1+il]=min(tab[c1+il],it); int ll=min(c1+il,A-a1); if(tab[c1+il-ll]>=it || tab[a1+ll]>=it) but(3,2,a1,b1-il,c1+il,it); ll=min(b1-il,A-a1); if(tab[b1-il-ll]>=it || tab[a1+ll]>=it) but(2,3,a1,b1-il,c1+il,it); but(1,0,a1,b1-il,c1+il,it); } } return ; } if(n==3) { if(p!=2) { int il=min(c1,B-b1); if(il) { tab[c1-il]=min(tab[c1-il],it); tab[b1+il]=min(tab[b1+il],it); int ll=min(b1+il,A-a1); if(tab[b1+il-ll]>=it || tab[a1+ll]>=it) but(2,3,a1,b1+il,c1-il,it); ll=min(c1-il,A-a1); if(tab[c1-il-ll]>=it || tab[a1+ll]>=it) but(3,2,a1,b1+il,c1-il,it); but(1,0,a1,b1+il,c1-il,it); } } if(p!=1) { int il=min(c1,A-a1); if(il) { tab[c1-il]=min(tab[c1-il],it); tab[a1+il]=min(tab[a1+il],it); int ll=min(a1+il,B-b1); if(tab[a1+il-ll]>=it || tab[b1+ll]>=it) but(1,3,a1+il,b1,c1-il,it); ll=min(c1-il,B-b1); if(tab[c1-il-ll]>=it || tab[b1+ll]>=it) but(3,1,a1+il,b1,c1-il,it); but(2,0,a1+il,b1,c1-il,it); } } return ; } return; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> A >> B >> C; cin >> a >> b >> c; for(int i=0;i<=C;i++) { tab[i]=inf; } tab[a]=0; tab[b]=0; tab[c]=0; but(1,0,a,b,c,0); but(2,0,a,b,c,0); but(3,0,a,b,c,0); for(int i=0;i<=C;i++) { if(tab[i]!=inf) cout << tab[i] << " "; else cout << "-1 "; } return(0); }
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 | #include<bits/stdc++.h> using namespace std; int A,B,C,a,b,c,tab[100007]; #define inf 10000000 void but(int n,int p,int a1,int b1, int c1,int it) { it++; if(it>C*2) return; if(n==1) { if(p!=2) { int il=min(a1,B-b1); if(il) { tab[a1-il]=min(tab[a1-il],it); tab[b1+il]=min(tab[b1+il],it); int ll=min(b1+il,C-c1); if(tab[b1+il-ll]>=it || tab[c1+ll]>=it) but(2,1,a1-il,b1+il,c1,it); ll=min(a1-il,C-c1); if(tab[a1-il-ll]>=it || tab[c1+ll]>=it) but(1,2,a1-il,b1+il,c1,it); but(3,0,a1-il,b1+il,c1,it); } } if(p!=3) { int il=min(a1,C-c1); if(il) { tab[a1-il]=min(tab[a1-il],it); tab[c1+il]=min(tab[c1+il],it); int ll=min(c1+il,B-b1); if(tab[c1+il-ll]>=it || tab[b1+ll]>=it) but(3,1,a1-il,b1,c1+il,it); ll=min(a1-il,B-b1); if(tab[a1-il-ll]>=it || tab[b1+ll]>=it) but(1,3,a1-il,b1,c1+il,it); but(2,0,a1-il,b1,c1+il,it); } } return ; } if(n==2) { if(p!=1) { int il=min(b1,A-a1); if(il) { tab[b1-il]=min(tab[b1-il],it); tab[a1+il]=min(tab[a1+il],it); int ll=min(a1+il,C-c1); if(tab[a1+il-ll]>=it || tab[c1+ll]>=it) but(1,2,a1+il,b1-il,c1,it); ll=min(b1-il,C-c1); if(tab[b1-il-ll]>=it || tab[c1+ll]>=it) but(2,1,a1+il,b1-il,c1,it); but(3,0,a1+il,b1-il,c1,it); } } if(p!=3) { int il=min(b1,C-c1); if(il) { tab[b1-il]=min(tab[b1-il],it); tab[c1+il]=min(tab[c1+il],it); int ll=min(c1+il,A-a1); if(tab[c1+il-ll]>=it || tab[a1+ll]>=it) but(3,2,a1,b1-il,c1+il,it); ll=min(b1-il,A-a1); if(tab[b1-il-ll]>=it || tab[a1+ll]>=it) but(2,3,a1,b1-il,c1+il,it); but(1,0,a1,b1-il,c1+il,it); } } return ; } if(n==3) { if(p!=2) { int il=min(c1,B-b1); if(il) { tab[c1-il]=min(tab[c1-il],it); tab[b1+il]=min(tab[b1+il],it); int ll=min(b1+il,A-a1); if(tab[b1+il-ll]>=it || tab[a1+ll]>=it) but(2,3,a1,b1+il,c1-il,it); ll=min(c1-il,A-a1); if(tab[c1-il-ll]>=it || tab[a1+ll]>=it) but(3,2,a1,b1+il,c1-il,it); but(1,0,a1,b1+il,c1-il,it); } } if(p!=1) { int il=min(c1,A-a1); if(il) { tab[c1-il]=min(tab[c1-il],it); tab[a1+il]=min(tab[a1+il],it); int ll=min(a1+il,B-b1); if(tab[a1+il-ll]>=it || tab[b1+ll]>=it) but(1,3,a1+il,b1,c1-il,it); ll=min(c1-il,B-b1); if(tab[c1-il-ll]>=it || tab[b1+ll]>=it) but(3,1,a1+il,b1,c1-il,it); but(2,0,a1+il,b1,c1-il,it); } } return ; } return; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> A >> B >> C; cin >> a >> b >> c; for(int i=0;i<=C;i++) { tab[i]=inf; } tab[a]=0; tab[b]=0; tab[c]=0; but(1,0,a,b,c,0); but(2,0,a,b,c,0); but(3,0,a,b,c,0); for(int i=0;i<=C;i++) { if(tab[i]!=inf) cout << tab[i] << " "; else cout << "-1 "; } return(0); } |