#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define all(x) (x).begin(), (x).end() #define mid (l+r)/2 #define PI acos((ld)-1) #define BOOST ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0) typedef long long ll; typedef long double ld; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<ii> vii; typedef vector<vi> vvi; int A, B, C, a, b, c; vi ans; map<pair<int, ii>, bool> vis; queue<vi> bfs; void akt(int x, int k){ if(ans[x] == -1) ans[x] = k; else ans[x] = min(ans[x], k); } void go(){ bfs.push({a, b, c, 0}); while(bfs.size()){ vi x = bfs.front(); bfs.pop(); if(vis[{x[0], {x[1], x[2]}}]) continue; vis[{x[0], {x[1], x[2]}}] = 1; akt(x[0], x[3]), akt(x[1], x[3]), akt(x[2], x[3]); bfs.push({x[0]-min(B-x[1], x[0]), x[1]+min(B-x[1], x[0]), x[2], x[3]+1}); bfs.push({x[0]-min(C-x[2], x[0]), x[1], x[2]+min(C-x[2], x[0]), x[3]+1}); bfs.push({x[0]+min(A-x[0], x[1]), x[1]-min(A-x[0], x[1]), x[2], x[3]+1}); bfs.push({x[0], x[1]-min(C-x[2], x[1]), x[2]+min(C-x[2], x[1]), x[3]+1}); bfs.push({x[0]+min(A-x[0], x[2]), x[1], x[2]-min(A-x[0], x[2]), x[3]+1}); bfs.push({x[0], x[1]+min(B-x[1], x[2]), x[2]-min(B-x[1], x[2]), x[3]+1}); } } int main(){ BOOST; cin >> A >> B >> C >> a >> b >> c; ans = vi(C+1, -1); go(); for(int i=0; i<=C; i++) cout << ans[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 53 54 55 56 | #include <bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define all(x) (x).begin(), (x).end() #define mid (l+r)/2 #define PI acos((ld)-1) #define BOOST ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0) typedef long long ll; typedef long double ld; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<ii> vii; typedef vector<vi> vvi; int A, B, C, a, b, c; vi ans; map<pair<int, ii>, bool> vis; queue<vi> bfs; void akt(int x, int k){ if(ans[x] == -1) ans[x] = k; else ans[x] = min(ans[x], k); } void go(){ bfs.push({a, b, c, 0}); while(bfs.size()){ vi x = bfs.front(); bfs.pop(); if(vis[{x[0], {x[1], x[2]}}]) continue; vis[{x[0], {x[1], x[2]}}] = 1; akt(x[0], x[3]), akt(x[1], x[3]), akt(x[2], x[3]); bfs.push({x[0]-min(B-x[1], x[0]), x[1]+min(B-x[1], x[0]), x[2], x[3]+1}); bfs.push({x[0]-min(C-x[2], x[0]), x[1], x[2]+min(C-x[2], x[0]), x[3]+1}); bfs.push({x[0]+min(A-x[0], x[1]), x[1]-min(A-x[0], x[1]), x[2], x[3]+1}); bfs.push({x[0], x[1]-min(C-x[2], x[1]), x[2]+min(C-x[2], x[1]), x[3]+1}); bfs.push({x[0]+min(A-x[0], x[2]), x[1], x[2]-min(A-x[0], x[2]), x[3]+1}); bfs.push({x[0], x[1]+min(B-x[1], x[2]), x[2]-min(B-x[1], x[2]), x[3]+1}); } } int main(){ BOOST; cin >> A >> B >> C >> a >> b >> c; ans = vi(C+1, -1); go(); for(int i=0; i<=C; i++) cout << ans[i] << " "; } |