//Autor: Bartłomiej Czarkowski #include <bits/stdc++.h> using namespace std; struct info { int t[3]; }; const int N = 1e5 + 7; info ogr, poc; int odp[N]; unordered_set <unsigned long long> mp; queue <pair<info, int>> que; unsigned long long war(info x) { return x.t[0] ^ ((long long) x.t[1] << 20) ^ ((long long) x.t[2] << 40); } info lej(info x, int p, int q) { // p -> q if (x.t[p] + x.t[q] >= ogr.t[q]) { // do pełna x.t[p] -= ogr.t[q] - x.t[q]; x.t[q] = ogr.t[q]; } else { // puste x.t[q] += x.t[p]; x.t[p] = 0; } return x; } int main() { for (int i = 0; i < 3; ++i) { scanf("%d", &ogr.t[i]); } for (int i = 0; i < 3; ++i) { scanf("%d", &poc.t[i]); } for (int i = 0; i <= ogr.t[2]; ++i) { odp[i] = 1e9; } que.push({poc, 0}); while (!que.empty()) { info x = que.front().first; int tm = que.front().second; que.pop(); for (int i = 0; i < 3; ++i) { odp[x.t[i]] = min(odp[x.t[i]], tm); } for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) { if (i == j) { continue; } info y = lej(x, i, j); unsigned long long w = war(y); if (!mp.count(w)) { que.push({y, tm + 1}); mp.insert(w); } } } } for (int i = 0; i <= ogr.t[2]; ++i) { if (odp[i] != 1e9) { printf("%d ", odp[i]); } else { printf("-1 "); } } printf("\n"); 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 | //Autor: Bartłomiej Czarkowski #include <bits/stdc++.h> using namespace std; struct info { int t[3]; }; const int N = 1e5 + 7; info ogr, poc; int odp[N]; unordered_set <unsigned long long> mp; queue <pair<info, int>> que; unsigned long long war(info x) { return x.t[0] ^ ((long long) x.t[1] << 20) ^ ((long long) x.t[2] << 40); } info lej(info x, int p, int q) { // p -> q if (x.t[p] + x.t[q] >= ogr.t[q]) { // do pełna x.t[p] -= ogr.t[q] - x.t[q]; x.t[q] = ogr.t[q]; } else { // puste x.t[q] += x.t[p]; x.t[p] = 0; } return x; } int main() { for (int i = 0; i < 3; ++i) { scanf("%d", &ogr.t[i]); } for (int i = 0; i < 3; ++i) { scanf("%d", &poc.t[i]); } for (int i = 0; i <= ogr.t[2]; ++i) { odp[i] = 1e9; } que.push({poc, 0}); while (!que.empty()) { info x = que.front().first; int tm = que.front().second; que.pop(); for (int i = 0; i < 3; ++i) { odp[x.t[i]] = min(odp[x.t[i]], tm); } for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) { if (i == j) { continue; } info y = lej(x, i, j); unsigned long long w = war(y); if (!mp.count(w)) { que.push({y, tm + 1}); mp.insert(w); } } } } for (int i = 0; i <= ogr.t[2]; ++i) { if (odp[i] != 1e9) { printf("%d ", odp[i]); } else { printf("-1 "); } } printf("\n"); return 0; } |