#include <cstdio> #include "message.h" #include "maklib.h" using namespace std; typedef long long int LL; int main(){ LL wyn = 0; LL w = 0; for (unsigned int i=MyNodeId(); i<Size(); i+=NumberOfNodes()){ w = ElementAt(i+1); for (LL j=i+1; j<Size(); ++j){ if (w>0) w += ElementAt(j+1); else break; } } if (w>0) wyn = w; if (MyNodeId()>0){ PutLL(0, w); Send(0); } else{ for (unsigned int i=1; i<NumberOfNodes(); ++i){ Receive(i); w = GetLL(i); if (w>wyn) wyn = w; } printf("%lld\n", wyn); } 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 | #include <cstdio> #include "message.h" #include "maklib.h" using namespace std; typedef long long int LL; int main(){ LL wyn = 0; LL w = 0; for (unsigned int i=MyNodeId(); i<Size(); i+=NumberOfNodes()){ w = ElementAt(i+1); for (LL j=i+1; j<Size(); ++j){ if (w>0) w += ElementAt(j+1); else break; } } if (w>0) wyn = w; if (MyNodeId()>0){ PutLL(0, w); Send(0); } else{ for (unsigned int i=1; i<NumberOfNodes(); ++i){ Receive(i); w = GetLL(i); if (w>wyn) wyn = w; } printf("%lld\n", wyn); } return 0; } |