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
#include <iostream>
#include <vector>
#include <queue>

constexpr int overflow = 10000;

struct visit {
	visit(int av, int bv, int step) : av(av), bv(bv), step(step) {}

	int av;
	int bv;
	int step;
};

int main() {
	int a, b, c;
	std::cin >> a >> b >> c;
	if (a * b > (overflow * overflow)) {
		for (int i = 0; i <= c; ++i) {
			std::cout << 0 << (i == c ? '\n' : ' ');
		}
		return 0;
	}
	
	std::vector<std::vector<int>> steps;
	steps.resize(a + 1);

	for (int i = 0; i <= a; ++i) {
		steps[i].resize(b + 1, -1);
	}

	int a_v, b_v, c_v;
	std::cin >> a_v >> b_v >> c_v;

	std::vector<int> solutions;
	solutions.resize(c + 1, -1);
	std::queue<visit> q;
	q.push(visit(a_v, b_v, 0));

	int total = a_v + b_v + c_v;

	while (!q.empty()) {
		visit v = q.front();
		q.pop();
		if (steps[v.av][v.bv] >= 0) continue;
		steps[v.av][v.bv] = v.step;
		int cv = total - v.av - v.bv;
		if (solutions[v.av] < 0) solutions[v.av] = v.step;
		if (solutions[v.bv] < 0) solutions[v.bv] = v.step;
		if (solutions[cv] < 0) solutions[cv] = v.step;
		if (v.bv < b) {
			int delta = b - v.bv;
			q.push(visit(v.av - std::min(v.av, delta), v.bv + std::min(v.av, delta), v.step + 1));
			q.push(visit(v.av, v.bv + std::min(cv, delta), v.step + 1));
		}
		if (v.av < a) {
			int delta = a - v.av;
			q.push(visit(v.av + std::min(v.bv, delta), v.bv - std::min(v.bv, delta), v.step + 1));
			q.push(visit(v.av + std::min(cv, delta), v.bv, v.step + 1));
		}
		if (cv < c) {
			int delta = c - cv;
			q.push(visit(v.av - std::min(v.av, delta), v.bv, v.step + 1));
			q.push(visit(v.av, v.bv - std::min(v.bv, delta), v.step + 1));
		}
	}


	for (int i = 0; i <= c; ++i) {
		std::cout << solutions[i] << (i == c ? '\n' : ' ');
	}

	return 0;
}