#include <bits/stdc++.h> using namespace std; //A1; 0 //A0; 1 //B1; 2 //B0; 3 //C1; 4 //C0; 5 set<pair<int, int>> s[6]; queue<pair<pair<int, int>, pair<int, int>>> q; int A, B, C; int best[100000 + 7]; int a, b, c, t; int newa, newb, newc; void przyporzadkuj() { a = q.front().first.first; b = q.front().first.second; c = q.front().second.first; t = q.front().second.second; q.pop(); bool lepiej = false; if(best[a] > t) best[a] = t, lepiej = true; if(best[b] > t) best[b] = t, lepiej = true; if(best[c] > t) best[c] = t, lepiej = true; if(a == A) { if(!lepiej and s[0].find({b, c}) != s[0].end()) return; else s[0].insert({b, c}); } if(a == 0) { if(!lepiej and s[1].find({b, c}) != s[1].end()) return; else s[1].insert({b, c}); } if(b == B) { if(!lepiej and s[2].find({a, c}) != s[2].end()) return; else s[2].insert({a, c}); } if(b == 0) { if(!lepiej and s[3].find({a, c}) != s[3].end()) return; else s[3].insert({a, c}); } if(c == C) { if(!lepiej and s[4].find({a, b}) != s[4].end()) return; else s[4].insert({a, b}); } if(c == 0) { if(!lepiej and s[5].find({a, b}) != s[5].end()) return; else s[5].insert({a, b}); } if(a < A) { newa = a; newb = b; newc = c; newa += min(A-a, b); newb -= min(A-a, b); q.push({{newa, newb}, {newc, t + 1}}); newa = a; newb = b; newc = c; newa += min(A-a, c); newc -= min(A-a, c); q.push({{newa, newb}, {newc, t + 1}}); } if(b < B) { newa = a; newb = b; newc = c; newb += min(B-b, a); newa -= min(B-b, a); q.push({{newa, newb}, {newc, t + 1}}); newa = a; newb = b; newc = c; newb += min(B-b, c); newc -= min(B-b, c); q.push({{newa, newb}, {newc, t + 1}}); } if(c < C) { newa = a; newb = b; newc = c; newc += min(C-c, b); newb -= min(C-c, b); q.push({{newa, newb}, {newc, t + 1}}); newa = a; newb = b; newc = c; newc += min(C-c, a); newa -= min(C-c, a); q.push({{newa, newb}, {newc, t + 1}}); } } void start() { while(!q.empty()) przyporzadkuj(); } void wypisz() { for(int i = 0; i <= C; i++) if(best[i] != 1000000000) cout << best[i] << ' '; else cout << -1 << ' '; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int a, b, c; cin >> A >> B >> C >> a >> b >> c; q.push({{a, b}, {c, 0}}); for(int i = 0; i <= C; i++) best[i] = 1000000000; start(); wypisz(); }
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 | #include <bits/stdc++.h> using namespace std; //A1; 0 //A0; 1 //B1; 2 //B0; 3 //C1; 4 //C0; 5 set<pair<int, int>> s[6]; queue<pair<pair<int, int>, pair<int, int>>> q; int A, B, C; int best[100000 + 7]; int a, b, c, t; int newa, newb, newc; void przyporzadkuj() { a = q.front().first.first; b = q.front().first.second; c = q.front().second.first; t = q.front().second.second; q.pop(); bool lepiej = false; if(best[a] > t) best[a] = t, lepiej = true; if(best[b] > t) best[b] = t, lepiej = true; if(best[c] > t) best[c] = t, lepiej = true; if(a == A) { if(!lepiej and s[0].find({b, c}) != s[0].end()) return; else s[0].insert({b, c}); } if(a == 0) { if(!lepiej and s[1].find({b, c}) != s[1].end()) return; else s[1].insert({b, c}); } if(b == B) { if(!lepiej and s[2].find({a, c}) != s[2].end()) return; else s[2].insert({a, c}); } if(b == 0) { if(!lepiej and s[3].find({a, c}) != s[3].end()) return; else s[3].insert({a, c}); } if(c == C) { if(!lepiej and s[4].find({a, b}) != s[4].end()) return; else s[4].insert({a, b}); } if(c == 0) { if(!lepiej and s[5].find({a, b}) != s[5].end()) return; else s[5].insert({a, b}); } if(a < A) { newa = a; newb = b; newc = c; newa += min(A-a, b); newb -= min(A-a, b); q.push({{newa, newb}, {newc, t + 1}}); newa = a; newb = b; newc = c; newa += min(A-a, c); newc -= min(A-a, c); q.push({{newa, newb}, {newc, t + 1}}); } if(b < B) { newa = a; newb = b; newc = c; newb += min(B-b, a); newa -= min(B-b, a); q.push({{newa, newb}, {newc, t + 1}}); newa = a; newb = b; newc = c; newb += min(B-b, c); newc -= min(B-b, c); q.push({{newa, newb}, {newc, t + 1}}); } if(c < C) { newa = a; newb = b; newc = c; newc += min(C-c, b); newb -= min(C-c, b); q.push({{newa, newb}, {newc, t + 1}}); newa = a; newb = b; newc = c; newc += min(C-c, a); newa -= min(C-c, a); q.push({{newa, newb}, {newc, t + 1}}); } } void start() { while(!q.empty()) przyporzadkuj(); } void wypisz() { for(int i = 0; i <= C; i++) if(best[i] != 1000000000) cout << best[i] << ' '; else cout << -1 << ' '; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int a, b, c; cin >> A >> B >> C >> a >> b >> c; q.push({{a, b}, {c, 0}}); for(int i = 0; i <= C; i++) best[i] = 1000000000; start(); wypisz(); } |