#include "palindromy.h" #include "message.h" #include <algorithm> #include <cstdio> using namespace std; typedef long long int lld; int sufprz(int a, int b) { if(a%b==0)return a/b; return a/b+1; } int main() { int N = NumberOfNodes(); int ja = MyNodeId(); int n = GetLength(); int dl=sufprz(n,N); int pocz=ja*dl; int kon=min(ja*dl + dl,n); if(pocz>=kon) { if(ja>0) { PutLL(0,0); Send(0); } return 0; } lld wyn=0; for(int i=pocz;i<kon;i++) { int dl=0; while(i-dl-1>=0 && i+dl+1<n && GetLetter(i-dl-1)==GetLetter(i+dl+1))dl++; wyn+=lld(dl+1); dl=0; while(i-dl-1>=0 && i+dl<n && GetLetter(i-dl-1)==GetLetter(i+dl))dl++; wyn+=lld(dl); } if(ja>0) { PutLL(0,wyn); Send(0); } else { for(int i=1;i<N;i++) { Receive(i); wyn+=GetLL(i); } printf("%lld\n",wyn); } }
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 | #include "palindromy.h" #include "message.h" #include <algorithm> #include <cstdio> using namespace std; typedef long long int lld; int sufprz(int a, int b) { if(a%b==0)return a/b; return a/b+1; } int main() { int N = NumberOfNodes(); int ja = MyNodeId(); int n = GetLength(); int dl=sufprz(n,N); int pocz=ja*dl; int kon=min(ja*dl + dl,n); if(pocz>=kon) { if(ja>0) { PutLL(0,0); Send(0); } return 0; } lld wyn=0; for(int i=pocz;i<kon;i++) { int dl=0; while(i-dl-1>=0 && i+dl+1<n && GetLetter(i-dl-1)==GetLetter(i+dl+1))dl++; wyn+=lld(dl+1); dl=0; while(i-dl-1>=0 && i+dl<n && GetLetter(i-dl-1)==GetLetter(i+dl))dl++; wyn+=lld(dl); } if(ja>0) { PutLL(0,wyn); Send(0); } else { for(int i=1;i<N;i++) { Receive(i); wyn+=GetLL(i); } printf("%lld\n",wyn); } } |