// Jedna instancja wypisuje maksymalny wzrost. #include "message.h" #include "teatr.h" #include "bits/stdc++.h" #define K 6 #define NODES 101 using namespace std; void instance() { int ret, i, j, s, e, x; int d[K]; long long int result = 0; for (i = 1; i < K; ++i) d[i] = 0; ret = Receive(0); s = GetInt(ret); if (s < 0) return; e = GetInt(ret); for (i = s; i <= e; ++i) { x = GetElement(i); if (x >= K) continue; d[x]++; for (j = x + 1; j < K; ++j) result += d[j]; } for (i = 1; i < K; ++i) { PutInt(0, d[i]); } PutLL(0, result); Send(0); } void manage() { int n, nodes, i, j, L; int d[NODES][K], dd[K]; long long int result = 0; for (i = 1; i < K; ++i) dd[i] = 0; nodes = NumberOfNodes(); n = GetN(); if (nodes - 1 > n) nodes = n + 1; L = n / (nodes - 1); for (i = nodes; i < NumberOfNodes(); ++i) { PutInt(i, -1); Send(i); } for (i = 1; i < nodes; ++i) { PutInt(i, (i - 1) * L); if (i == nodes - 1) PutInt(i, n - 1); else PutInt(i, i * L - 1); Send(i); } for (i = 1; i < nodes; ++i) { Receive(i); for (j = 1; j < K; ++j) d[i][j] = GetInt(i); result += GetLL(i); } for (i = 1; i < nodes; ++i) { for (j = 1; j < K; ++j) { for (int k = j + 1; k < K; ++k) result += dd[k] * d[i][j]; } for (j = 1; j < K; ++j) dd[j] += d[i][j]; } cout << result << "\n"; } int main() { int id; id = MyNodeId(); if (id == 0) manage(); else instance(); 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 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 | // Jedna instancja wypisuje maksymalny wzrost. #include "message.h" #include "teatr.h" #include "bits/stdc++.h" #define K 6 #define NODES 101 using namespace std; void instance() { int ret, i, j, s, e, x; int d[K]; long long int result = 0; for (i = 1; i < K; ++i) d[i] = 0; ret = Receive(0); s = GetInt(ret); if (s < 0) return; e = GetInt(ret); for (i = s; i <= e; ++i) { x = GetElement(i); if (x >= K) continue; d[x]++; for (j = x + 1; j < K; ++j) result += d[j]; } for (i = 1; i < K; ++i) { PutInt(0, d[i]); } PutLL(0, result); Send(0); } void manage() { int n, nodes, i, j, L; int d[NODES][K], dd[K]; long long int result = 0; for (i = 1; i < K; ++i) dd[i] = 0; nodes = NumberOfNodes(); n = GetN(); if (nodes - 1 > n) nodes = n + 1; L = n / (nodes - 1); for (i = nodes; i < NumberOfNodes(); ++i) { PutInt(i, -1); Send(i); } for (i = 1; i < nodes; ++i) { PutInt(i, (i - 1) * L); if (i == nodes - 1) PutInt(i, n - 1); else PutInt(i, i * L - 1); Send(i); } for (i = 1; i < nodes; ++i) { Receive(i); for (j = 1; j < K; ++j) d[i][j] = GetInt(i); result += GetLL(i); } for (i = 1; i < nodes; ++i) { for (j = 1; j < K; ++j) { for (int k = j + 1; k < K; ++k) result += dd[k] * d[i][j]; } for (j = 1; j < K; ++j) dd[j] += d[i][j]; } cout << result << "\n"; } int main() { int id; id = MyNodeId(); if (id == 0) manage(); else instance(); return 0; } |