#include <iostream> #include <algorithm> #include "message.h" #include "kanapka.h" using namespace std; int main() { long long sandwich_lenght = GetN(), max_sum = 0, sum[2] = { 0 , 0 }; const unsigned long long instance_index = MyNodeId(), number_of_instances = NumberOfNodes(); for (unsigned long long j = 0; j < instance_index; j++) { sum[0] += GetTaste(j); } max_sum = max(sum[0], max_sum); for (unsigned long long j = sandwich_lenght - 1; j >= instance_index; j--) { sum[1] += GetTaste(j); max_sum = max(sum[0] + sum[1], max_sum); } for (unsigned long long index = instance_index; index < sandwich_lenght - number_of_instances; index += number_of_instances) { for (unsigned long long j = index; j < index + instance_index; j++) { sum[0] += GetTaste(j); } max_sum = max(sum[0], max_sum); for (unsigned long long j = sandwich_lenght - 1; j >= index + number_of_instances; j--) { sum[1] += GetTaste(j); max_sum = max(sum[0] + sum[1], max_sum); } sum[1] = 0; } if (instance_index != 0) { PutLL(0, max_sum); Send(0); } else { for (unsigned long long i = 1; i < number_of_instances; i++) { Receive(i); max_sum = max(GetLL(i), max_sum); } cout << max_sum; } 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 | #include <iostream> #include <algorithm> #include "message.h" #include "kanapka.h" using namespace std; int main() { long long sandwich_lenght = GetN(), max_sum = 0, sum[2] = { 0 , 0 }; const unsigned long long instance_index = MyNodeId(), number_of_instances = NumberOfNodes(); for (unsigned long long j = 0; j < instance_index; j++) { sum[0] += GetTaste(j); } max_sum = max(sum[0], max_sum); for (unsigned long long j = sandwich_lenght - 1; j >= instance_index; j--) { sum[1] += GetTaste(j); max_sum = max(sum[0] + sum[1], max_sum); } for (unsigned long long index = instance_index; index < sandwich_lenght - number_of_instances; index += number_of_instances) { for (unsigned long long j = index; j < index + instance_index; j++) { sum[0] += GetTaste(j); } max_sum = max(sum[0], max_sum); for (unsigned long long j = sandwich_lenght - 1; j >= index + number_of_instances; j--) { sum[1] += GetTaste(j); max_sum = max(sum[0] + sum[1], max_sum); } sum[1] = 0; } if (instance_index != 0) { PutLL(0, max_sum); Send(0); } else { for (unsigned long long i = 1; i < number_of_instances; i++) { Receive(i); max_sum = max(GetLL(i), max_sum); } cout << max_sum; } return 0; } |