#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> PII; typedef pair<ll, ll> PLL; typedef pair<ld, ld> PLD; typedef vector<int> VI; typedef vector<ll> VL; typedef vector<PII> VII; typedef vector<VI> VVI; typedef vector<VL> VVL; typedef vector<VII> VVII; typedef vector<PLL> VLL; typedef vector<VLL> VVLL; typedef vector<VI> VVI; typedef vector<VL> VVL; typedef vector<bool> VB; typedef map<int, int> MII; typedef unordered_map<int, int> UMII; typedef map<ll, ll> MLL; typedef unordered_map<ll, ll> UMLL; template <class T, class G> ostream &operator<<(ostream &os, const pair<T, G> ¶) { os << para.first << " " << para.second; return os; } template <class T> ostream &operator<<(ostream &os, const vector<T> &vec) { for (const T &el : vec) os << el << " "; return os; } template <class T> ostream &operator<<(ostream &os, const set<T> &vec) { for (const T &el : vec) os << el << " "; return os; } #define REP(i, j) for (int i = 0; i < j; i++) #define REP1(i, j) for (int i = 1; i < j; i++) #define FOREACH(el, n) for (auto &el : n) #define LAST(x) (x[(int)x.size() - 1]) #define pb push_back #define pf push_front #define st first #define nd second #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define get_unique(x) x.erase(unique(all(x)), x.end()); #define sp ' ' #define ent '\n' struct state { int a, b, c; }; bool operator<(const state &x, const state &y) { pair<int, PII> px = {x.a, {x.b, x.c}}; pair<int, PII> py = {y.a, {y.b, y.c}}; return px < py; } struct comp { bool operator()(pair<int, state> const &xx, pair<int, state> const &yy) { auto [distx, x] = xx; auto [disty, y] = yy; pair<PII, PII> px = {{-distx, x.a}, {x.b, x.c}}; pair<PII, PII> py = {{-disty, y.a}, {y.b, y.c}}; return px < py; } }; void TEST(int testcase_i) { // TESTCASE VI dp(4e5, -1); int A, B, C; cin >> A >> B >> C; int a, b, c; cin >> a >> b >> c; priority_queue<pair<int, state>, vector<pair<int, state>>, comp> pq; set<state> used; pq.push({0, {a, b, c}}); while (!pq.empty()) { auto [dist, v] = pq.top(); pq.pop(); if (used.count(v)) { continue; } used.insert(v); if (dp[v.a] == -1) { dp[v.a] = dist; } if (dp[v.b] == -1) { dp[v.b] = dist; } if (dp[v.c] == -1) { dp[v.c] = dist; } int f1t2 = min(v.a, B - v.b); int f1t3 = min(v.a, C - v.c); int f2t1 = min(v.b, A - v.a); int f2t3 = min(v.b, C - v.c); int f3t1 = min(v.c, A - v.a); int f3t2 = min(v.c, B - v.b); state s1 = {v.a - f1t2, v.b + f1t2, v.c}; state s2 = {v.a - f1t3, v.b, v.c + f1t3}; state s3 = {v.a + f2t1, v.b - f2t1, v.c}; state s4 = {v.a, v.b - f2t3, v.c + f2t3}; state s5 = {v.a + f3t1, v.b, v.c - f3t1}; state s6 = {v.a, v.b + f3t2, v.c - f3t2}; pq.push({dist + 1, s1}); pq.push({dist + 1, s2}); pq.push({dist + 1, s3}); pq.push({dist + 1, s4}); pq.push({dist + 1, s5}); pq.push({dist + 1, s6}); } REP(i, C + 1) { cout << dp[i] << sp; } } int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); int t = 1; // cin >> t; REP(i, t) { TEST(i); } 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 134 | #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> PII; typedef pair<ll, ll> PLL; typedef pair<ld, ld> PLD; typedef vector<int> VI; typedef vector<ll> VL; typedef vector<PII> VII; typedef vector<VI> VVI; typedef vector<VL> VVL; typedef vector<VII> VVII; typedef vector<PLL> VLL; typedef vector<VLL> VVLL; typedef vector<VI> VVI; typedef vector<VL> VVL; typedef vector<bool> VB; typedef map<int, int> MII; typedef unordered_map<int, int> UMII; typedef map<ll, ll> MLL; typedef unordered_map<ll, ll> UMLL; template <class T, class G> ostream &operator<<(ostream &os, const pair<T, G> ¶) { os << para.first << " " << para.second; return os; } template <class T> ostream &operator<<(ostream &os, const vector<T> &vec) { for (const T &el : vec) os << el << " "; return os; } template <class T> ostream &operator<<(ostream &os, const set<T> &vec) { for (const T &el : vec) os << el << " "; return os; } #define REP(i, j) for (int i = 0; i < j; i++) #define REP1(i, j) for (int i = 1; i < j; i++) #define FOREACH(el, n) for (auto &el : n) #define LAST(x) (x[(int)x.size() - 1]) #define pb push_back #define pf push_front #define st first #define nd second #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define get_unique(x) x.erase(unique(all(x)), x.end()); #define sp ' ' #define ent '\n' struct state { int a, b, c; }; bool operator<(const state &x, const state &y) { pair<int, PII> px = {x.a, {x.b, x.c}}; pair<int, PII> py = {y.a, {y.b, y.c}}; return px < py; } struct comp { bool operator()(pair<int, state> const &xx, pair<int, state> const &yy) { auto [distx, x] = xx; auto [disty, y] = yy; pair<PII, PII> px = {{-distx, x.a}, {x.b, x.c}}; pair<PII, PII> py = {{-disty, y.a}, {y.b, y.c}}; return px < py; } }; void TEST(int testcase_i) { // TESTCASE VI dp(4e5, -1); int A, B, C; cin >> A >> B >> C; int a, b, c; cin >> a >> b >> c; priority_queue<pair<int, state>, vector<pair<int, state>>, comp> pq; set<state> used; pq.push({0, {a, b, c}}); while (!pq.empty()) { auto [dist, v] = pq.top(); pq.pop(); if (used.count(v)) { continue; } used.insert(v); if (dp[v.a] == -1) { dp[v.a] = dist; } if (dp[v.b] == -1) { dp[v.b] = dist; } if (dp[v.c] == -1) { dp[v.c] = dist; } int f1t2 = min(v.a, B - v.b); int f1t3 = min(v.a, C - v.c); int f2t1 = min(v.b, A - v.a); int f2t3 = min(v.b, C - v.c); int f3t1 = min(v.c, A - v.a); int f3t2 = min(v.c, B - v.b); state s1 = {v.a - f1t2, v.b + f1t2, v.c}; state s2 = {v.a - f1t3, v.b, v.c + f1t3}; state s3 = {v.a + f2t1, v.b - f2t1, v.c}; state s4 = {v.a, v.b - f2t3, v.c + f2t3}; state s5 = {v.a + f3t1, v.b, v.c - f3t1}; state s6 = {v.a, v.b + f3t2, v.c - f3t2}; pq.push({dist + 1, s1}); pq.push({dist + 1, s2}); pq.push({dist + 1, s3}); pq.push({dist + 1, s4}); pq.push({dist + 1, s5}); pq.push({dist + 1, s6}); } REP(i, C + 1) { cout << dp[i] << sp; } } int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); int t = 1; // cin >> t; REP(i, t) { TEST(i); } return 0; } |