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

std::set <uint64_t> found;
std::array <int, 100001> layer;
int found_layers = 0;

int main()
{
	uint64_t ma, mb, mc;
	std::cin >> ma >> mb >> mc;

	uint64_t sa, sb, sc;
	std::cin >> sa >> sb >> sc;

	for (int i = 0; i <= mc; ++i) {
		layer[i] = -1;
	}

	uint64_t sx = sa + 100001 * sb + sc * 10000200001;
	found.insert(sx);

			uint64_t aa = sx % 100001;
			uint64_t bb = (sx / 100001) % 100001;
			uint64_t cc = sx / 10000200001;

	//std::cout << "sx " << sx << " aka " << aa << " / " << bb << " / " << cc << std::endl;

	int current_layer = 0;
	std::vector <uint64_t> current_combos(1, sx);
	while (!current_combos.empty() && found_layers <= mc) {
//std::cout << "currlayer " << current_layer << ", " << current_combos.size() << " combos to process" << std::endl;
		std::vector <uint64_t> next_combos;
		for (int i = 0, s = current_combos.size(); i < s; ++i) {
			uint64_t x = current_combos[i];
			uint64_t a = x % 100001;
			uint64_t b = (x / 100001) % 100001;
			uint64_t c = x / 10000200001;
//std::cout << "combo: " << x << " aka " << a << " / " << b << " / " << c << std::endl;

			if (layer[a] == -1) {
				layer[a] = current_layer;
				++found_layers;
			}
			if (layer[b] == -1) {
				layer[b] = current_layer;
				++found_layers;
			}
			if (layer[c] == -1) {
				layer[c] = current_layer;
				++found_layers;
			}

			if (a > 0) {
				uint64_t pac = std::min(mc - c, a);
				uint64_t lac = (a - pac) + 100001 * b + (c + pac) * 10000200001;
				auto it1 = found.insert(lac);
				if (it1.second)
					next_combos.push_back(lac);

				uint64_t pab = std::min(mb - b, a);
				uint64_t lab = (a - pab) + 100001 * (b + pab) + c * 10000200001;
				auto it2 = found.insert(lab);
				if (it2.second)
					next_combos.push_back(lab);
			}

			if (b > 0) {
				uint64_t pbc = std::min(mc - c, b);
				uint64_t lbc = a + 100001 * (b - pbc) + (c + pbc) * 10000200001;
				auto it1 = found.insert(lbc);
				if (it1.second)
					next_combos.push_back(lbc);

				uint64_t pba = std::min(ma - a, b);
				uint64_t lba = (a + pba) + 100001 * (b - pba) + c * 10000200001;
				auto it2 = found.insert(lba);
				if (it2.second)
					next_combos.push_back(lba);
			}

			if (c > 0) {
				uint64_t pca = std::min(ma - a, c);
				uint64_t lca = (a + pca) + 100001 * b + (c - pca) * 10000200001;
				auto it1 = found.insert(lca);
				if (it1.second)
					next_combos.push_back(lca);

				uint64_t pcb = std::min(mb - b, c);
				uint64_t lcb = a + 100001 * (b + pcb) + (c - pcb) * 10000200001;
				auto it2 = found.insert(lcb);
				if (it2.second)
					next_combos.push_back(lcb);
			}
		}

		current_combos = std::move(next_combos);
		++ current_layer;


	//for (int i = 0; i <= mc; ++i)
	//	std::cout << layer[i] << " ";
	//std::cout << std::endl;
	}

	for (int i = 0; i <= mc; ++i)
		std::cout << layer[i] << " ";
	std::cout << std::endl;

	return 0;
}