#include "kanapka.h" #include "message.h" #include <stdio.h> long long t[400]; int main() { long long N, L, H; N = GetN(); if (N < NumberOfNodes()) { if (MyNodeId() > 0) return 0; L = 0; H = N; } else { L = N* MyNodeId() /NumberOfNodes(); H = N*(MyNodeId()+1)/NumberOfNodes(); } long long i, s=0, x=0, n=0, m=0, h=0; for (i=L; i<H; i++) { s += GetTaste(i); if (s>x) x=s, m=s; if (s<n) n=s; if (m-s>h) h=m-s; } long long l=0; // n,x-n,-h,s-x+h // 0 n x x-h s if (MyNodeId() > 0) { PutLL(0, n); PutLL(0, x-n); PutLL(0, -h); PutLL(0, s-x+h); Send(0); return 0; } t[l++] = n; t[l++] = x-n; t[l++] = -h; t[l++] = s-x+h; if (H<N) for (i=1; i<NumberOfNodes(); i++) { Receive(i); t[l++] = GetLL(i); t[l++] = GetLL(i); t[l++] = GetLL(i); t[l++] = GetLL(i); } s=0, x=0, n=0, m=0, h=0; for (i=0; i<l; i++) { s += t[i]; if (s>x) x=s, m=s; if (s<n) n=s; if (m-s>h) h=m-s; } printf("%lld\n",s+h); 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 | #include "kanapka.h" #include "message.h" #include <stdio.h> long long t[400]; int main() { long long N, L, H; N = GetN(); if (N < NumberOfNodes()) { if (MyNodeId() > 0) return 0; L = 0; H = N; } else { L = N* MyNodeId() /NumberOfNodes(); H = N*(MyNodeId()+1)/NumberOfNodes(); } long long i, s=0, x=0, n=0, m=0, h=0; for (i=L; i<H; i++) { s += GetTaste(i); if (s>x) x=s, m=s; if (s<n) n=s; if (m-s>h) h=m-s; } long long l=0; // n,x-n,-h,s-x+h // 0 n x x-h s if (MyNodeId() > 0) { PutLL(0, n); PutLL(0, x-n); PutLL(0, -h); PutLL(0, s-x+h); Send(0); return 0; } t[l++] = n; t[l++] = x-n; t[l++] = -h; t[l++] = s-x+h; if (H<N) for (i=1; i<NumberOfNodes(); i++) { Receive(i); t[l++] = GetLL(i); t[l++] = GetLL(i); t[l++] = GetLL(i); t[l++] = GetLL(i); } s=0, x=0, n=0, m=0, h=0; for (i=0; i<l; i++) { s += t[i]; if (s>x) x=s, m=s; if (s<n) n=s; if (m-s>h) h=m-s; } printf("%lld\n",s+h); return 0; } |