#include "message.h"
#include "maklib.h"
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
vector<int> pocz,koniec,pomoc;
int result;
int length, na_stacje,nadrob;
int ile;
void start(){
ile = NumberOfNodes();
length = Size();
na_stacje = length/NumberOfNodes();
nadrob = length%NumberOfNodes();
pocz.resize(ile+1,0);
koniec.resize(ile+1,0);
pomoc.resize(ile+1,0);
return;
}
/*
void licz(int k){
while(MyNodeId()==k){
bool zapadka = false;
long long pomoc;
for(int i = 0; i < 10000000; i++){
if(Size()>=10000000*k+i){
pomoc += ElementAt(i+k*10000000);
if(pomoc < 0){
pomoc = 0;
zapadka = true;
}
if(!zapadka) pocz[k] = max(pocz[k],pomoc);
result = max(result,pomoc);
koniec[k] = pomoc;
}
else break;
}
return;
}
return;
}*/
void licz(int k){
int zwr_pocz=0,zwr_kon=0,zwr_max;
if(MyNodeId()==k){
bool zapadka = false;
int pomoc = 0;
for(int i = 0; i < na_stacje; i++){
if(Size()>=((na_stacje*k)+i)){
pomoc += ElementAt(((na_stacje*k)+i));
if(pomoc = 0)
pomoc = 0;
zwr_max = max(zwr_max,pomoc);
if(!zapadka) zwr_pocz = max(zwr_pocz,pomoc);
zwr_kon = pomoc;
}
else
break;
}
PutInt(1,zwr_pocz);
PutInt(1,zwr_kon);
PutInt(1,zwr_max);
Send(1);
return;
}
return;
}
void odb(){
int k = 1;
while(k<=ile){
Receive(k);
int war_pocz,war_kon,war_max;
war_pocz = GetInt(k);
war_kon = GetInt(k);
war_max = GetInt(k);
result = max(result,war_max);
pocz[k] = war_pocz;
koniec[k] = war_kon;
k++;
}
return;
}
void poczatki(){
for(int i = 2; i <= NumberOfNodes(); i++)
result = max(result,pocz[i-1]+koniec[i]);
return;
}
int main(){
start();
for(int i = 1; i <= ile; i++)
licz(i);
if(MyNodeId()==1){
odb();
poczatki();
printf("%d\n",result);
}
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 105 106 107 108 109 110 111 | #include "message.h" #include "maklib.h" #include <cstdio> #include <algorithm> #include <cmath> #include <vector> using namespace std; vector<int> pocz,koniec,pomoc; int result; int length, na_stacje,nadrob; int ile; void start(){ ile = NumberOfNodes(); length = Size(); na_stacje = length/NumberOfNodes(); nadrob = length%NumberOfNodes(); pocz.resize(ile+1,0); koniec.resize(ile+1,0); pomoc.resize(ile+1,0); return; } /* void licz(int k){ while(MyNodeId()==k){ bool zapadka = false; long long pomoc; for(int i = 0; i < 10000000; i++){ if(Size()>=10000000*k+i){ pomoc += ElementAt(i+k*10000000); if(pomoc < 0){ pomoc = 0; zapadka = true; } if(!zapadka) pocz[k] = max(pocz[k],pomoc); result = max(result,pomoc); koniec[k] = pomoc; } else break; } return; } return; }*/ void licz(int k){ int zwr_pocz=0,zwr_kon=0,zwr_max; if(MyNodeId()==k){ bool zapadka = false; int pomoc = 0; for(int i = 0; i < na_stacje; i++){ if(Size()>=((na_stacje*k)+i)){ pomoc += ElementAt(((na_stacje*k)+i)); if(pomoc = 0) pomoc = 0; zwr_max = max(zwr_max,pomoc); if(!zapadka) zwr_pocz = max(zwr_pocz,pomoc); zwr_kon = pomoc; } else break; } PutInt(1,zwr_pocz); PutInt(1,zwr_kon); PutInt(1,zwr_max); Send(1); return; } return; } void odb(){ int k = 1; while(k<=ile){ Receive(k); int war_pocz,war_kon,war_max; war_pocz = GetInt(k); war_kon = GetInt(k); war_max = GetInt(k); result = max(result,war_max); pocz[k] = war_pocz; koniec[k] = war_kon; k++; } return; } void poczatki(){ for(int i = 2; i <= NumberOfNodes(); i++) result = max(result,pocz[i-1]+koniec[i]); return; } int main(){ start(); for(int i = 1; i <= ile; i++) licz(i); if(MyNodeId()==1){ odb(); poczatki(); printf("%d\n",result); } return 0; } |
English