#include <bits/stdc++.h>
#define PB push_back
#define ST first
#define ND second
//#pragma GCC optimize ("O3")
//#pragma GCC target("tune=native")
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
using namespace std;
using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
const int nax = 1e5 + 10, INF = 1e9;
int lim[3];
int cur[3];
map<tuple<int,int,int>, int>states;
queue<tuple<int,int,int>>Q;
int ans[nax];
void mv(int &x, int &y, int Y) {
int yp = min(Y, x + y);
int xp = x + y - yp;
x = xp;
y = yp;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> lim[0] >> lim[1] >> lim[2] >> cur[0] >> cur[1] >> cur[2];
Q.push({cur[0], cur[1], cur[2]});
states[{cur[0], cur[1], cur[2]}] = 0;
while(!Q.empty()) {
auto [x,y,z] = Q.front();
int d = states[Q.front()];
Q.pop();
for(int i = 0; i < 3; ++i) {
for(int j = 0; j < 3; ++j) {
if(i == j) continue;
cur[0] = x, cur[1] = y, cur[2] = z;
mv(cur[i], cur[j], lim[j]);
if(!states.count({cur[0], cur[1], cur[2]})) {
states[{cur[0], cur[1], cur[2]}] = d + 1;
Q.push({cur[0], cur[1], cur[2]});
}
}
}
}
for(int i = 0; i <= lim[2]; ++i) {
ans[i] = INF;
}
for(auto s : states) {
auto [x,y,z] = s.ST;
ans[x] = min(ans[x], s.ND);
ans[y] = min(ans[y], s.ND);
ans[z] = min(ans[z], s.ND);
}
for(int i = 0; i <= lim[2]; ++i) {
if(ans[i] == INF) cout << "-1 ";
else 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 57 58 59 60 61 62 63 64 65 66 67 68 69 | #include <bits/stdc++.h> #define PB push_back #define ST first #define ND second //#pragma GCC optimize ("O3") //#pragma GCC target("tune=native") //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> //using namespace __gnu_pbds; //typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; using namespace std; using ll = long long; using pi = pair<int, int>; using vi = vector<int>; const int nax = 1e5 + 10, INF = 1e9; int lim[3]; int cur[3]; map<tuple<int,int,int>, int>states; queue<tuple<int,int,int>>Q; int ans[nax]; void mv(int &x, int &y, int Y) { int yp = min(Y, x + y); int xp = x + y - yp; x = xp; y = yp; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> lim[0] >> lim[1] >> lim[2] >> cur[0] >> cur[1] >> cur[2]; Q.push({cur[0], cur[1], cur[2]}); states[{cur[0], cur[1], cur[2]}] = 0; while(!Q.empty()) { auto [x,y,z] = Q.front(); int d = states[Q.front()]; Q.pop(); for(int i = 0; i < 3; ++i) { for(int j = 0; j < 3; ++j) { if(i == j) continue; cur[0] = x, cur[1] = y, cur[2] = z; mv(cur[i], cur[j], lim[j]); if(!states.count({cur[0], cur[1], cur[2]})) { states[{cur[0], cur[1], cur[2]}] = d + 1; Q.push({cur[0], cur[1], cur[2]}); } } } } for(int i = 0; i <= lim[2]; ++i) { ans[i] = INF; } for(auto s : states) { auto [x,y,z] = s.ST; ans[x] = min(ans[x], s.ND); ans[y] = min(ans[y], s.ND); ans[z] = min(ans[z], s.ND); } for(int i = 0; i <= lim[2]; ++i) { if(ans[i] == INF) cout << "-1 "; else cout << ans[i] << " "; } } |
English