//Patryk Kisielewski - PA 2016 - Kanapka [KAN] - v4.0 #include <cstdio> #include <vector> #include "kanapka.h" #include "message.h" using namespace std; int main(){ long long n = GetN(); vector<long long> sum; long long tmp; long long minimum; long long minimum_index = 0; sum.push_back(GetTaste(0)); minimum = sum[0]; for(long long i = 1; i < n; i++){ sum.push_back(sum[i-1]+GetTaste(i)); if(minimum >= sum[i]){ minimum = sum[i]; minimum_index = i; } } for(int i = minimum_index-1-MyNodeId(); i >= 0; i -= NumberOfNodes()){ tmp = sum[minimum_index]-sum[i]; if(minimum > tmp){ minimum = tmp; } } if(MyNodeId() > 0){ PutLL(0, minimum); Send(0); } else { for(int instancja = 1; instancja < NumberOfNodes(); ++instancja){ Receive(instancja); tmp = GetLL(instancja); if(tmp < minimum) minimum = tmp; } if(minimum > 0) minimum = 0; tmp = sum[n-1]-minimum; if(tmp > 0) printf("%lld\n", tmp); else printf("0\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 | //Patryk Kisielewski - PA 2016 - Kanapka [KAN] - v4.0 #include <cstdio> #include <vector> #include "kanapka.h" #include "message.h" using namespace std; int main(){ long long n = GetN(); vector<long long> sum; long long tmp; long long minimum; long long minimum_index = 0; sum.push_back(GetTaste(0)); minimum = sum[0]; for(long long i = 1; i < n; i++){ sum.push_back(sum[i-1]+GetTaste(i)); if(minimum >= sum[i]){ minimum = sum[i]; minimum_index = i; } } for(int i = minimum_index-1-MyNodeId(); i >= 0; i -= NumberOfNodes()){ tmp = sum[minimum_index]-sum[i]; if(minimum > tmp){ minimum = tmp; } } if(MyNodeId() > 0){ PutLL(0, minimum); Send(0); } else { for(int instancja = 1; instancja < NumberOfNodes(); ++instancja){ Receive(instancja); tmp = GetLL(instancja); if(tmp < minimum) minimum = tmp; } if(minimum > 0) minimum = 0; tmp = sum[n-1]-minimum; if(tmp > 0) printf("%lld\n", tmp); else printf("0\n"); } return 0; } |