#include <algorithm> #include <iostream> #include "krazki.h" #include "message.h" using namespace std; long long n,m; long long t[200000005]; int main() { long long id,non,res,frm,to,x,minnn,maxxx,ZERO=0; n=PipeHeight(); m=NumberOfDiscs(); id=MyNodeId(); non=NumberOfNodes(); if(m%non==0) { frm=(non-id-1)*(m/non)+1; to=frm+(m/non)-1; } else { frm=(non-id-1)*((m/non)+1)+1; to=min(to=frm+((m/non)+1)-1,m); } res=n; t[0]=1000000001L; for(long long i=1;i<=n;i++) { x=HoleDiameter(i); t[i]=min(x,t[i-1]); } for(long long i=frm;i<=to;i++) { x=DiscDiameter(i); while (res>0 && t[res]<x){res--; } res--; if (minnn==-1) minnn=max(ZERO,res+1); } maxxx=max(ZERO,res+1); if (id == non-1) { PutLL(id-1, maxxx); Send(id-1); } else if (id > 0) { Receive(id+1); x=GetLL(id+1); if(x>=minnn) { maxxx=x-(to-frm+1); } maxxx=max(maxxx,ZERO); PutLL(id-1, maxxx); Send(id-1); } else { Receive(id+1); x=GetLL(id+1); //cout } 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 | #include <algorithm> #include <iostream> #include "krazki.h" #include "message.h" using namespace std; long long n,m; long long t[200000005]; int main() { long long id,non,res,frm,to,x,minnn,maxxx,ZERO=0; n=PipeHeight(); m=NumberOfDiscs(); id=MyNodeId(); non=NumberOfNodes(); if(m%non==0) { frm=(non-id-1)*(m/non)+1; to=frm+(m/non)-1; } else { frm=(non-id-1)*((m/non)+1)+1; to=min(to=frm+((m/non)+1)-1,m); } res=n; t[0]=1000000001L; for(long long i=1;i<=n;i++) { x=HoleDiameter(i); t[i]=min(x,t[i-1]); } for(long long i=frm;i<=to;i++) { x=DiscDiameter(i); while (res>0 && t[res]<x){res--; } res--; if (minnn==-1) minnn=max(ZERO,res+1); } maxxx=max(ZERO,res+1); if (id == non-1) { PutLL(id-1, maxxx); Send(id-1); } else if (id > 0) { Receive(id+1); x=GetLL(id+1); if(x>=minnn) { maxxx=x-(to-frm+1); } maxxx=max(maxxx,ZERO); PutLL(id-1, maxxx); Send(id-1); } else { Receive(id+1); x=GetLL(id+1); //cout } return 0; } |