#include <bits/stdc++.h> #include "message.h" #include "kanapka.h" using namespace std; // int ilen; int ilej; int podz; int odd, dod; // int n; long long maxpretu, maxsuftu, maxogtu, ogtu; long long licz; long long najw; // vector < long long > og; vector < long long > wynog; vector < long long > wynpre; vector < long long > wynsuf; long long wyn; long long aktu; // int main() { n=GetN(); ilen=NumberOfNodes(); ilej=MyNodeId(); podz=n/ilen; odd=ilej*podz; dod=(ilej+1)*podz-1; if (ilej==ilen-1) dod=n-1; for (int i=odd; i<=dod; i++) { licz+=GetTaste(i); maxpretu=max(maxpretu, licz); } ogtu=licz; licz=0; for (int i=dod; i>=odd; i--) { licz+=GetTaste(i); maxsuftu=max(maxsuftu, licz); } licz=0; for (int i=odd; i<=dod; i++) { licz+=GetTaste(i); najw=max(najw, licz); maxogtu=max(maxogtu, ogtu-licz+najw); } PutLL(0, maxogtu); PutLL(0, maxpretu); PutLL(0, maxsuftu); PutLL(0, ogtu); Send(0); if (ilej) { return 0; } for (int i=0; i<ilen; i++) { Receive(i); wynog.push_back(GetLL(i)); wynpre.push_back(GetLL(i)); wynsuf.push_back(GetLL(i)); og.push_back(GetLL(i)); } for (int i=0; i<ilen; i++) { for (int j=i; j<ilen; j++) { aktu=0; for (int l=0; l<ilen; l++) { if (l<i || l>j) { aktu+=og[l]; continue; } if (l==i && l==j) { aktu+=wynog[l]; continue; } if (l==i) { aktu+=wynpre[l]; continue; } if (l==j) { aktu+=wynsuf[l]; continue; } } wyn=max(wyn, aktu); } } 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 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 112 113 114 115 116 117 118 119 | #include <bits/stdc++.h> #include "message.h" #include "kanapka.h" using namespace std; // int ilen; int ilej; int podz; int odd, dod; // int n; long long maxpretu, maxsuftu, maxogtu, ogtu; long long licz; long long najw; // vector < long long > og; vector < long long > wynog; vector < long long > wynpre; vector < long long > wynsuf; long long wyn; long long aktu; // int main() { n=GetN(); ilen=NumberOfNodes(); ilej=MyNodeId(); podz=n/ilen; odd=ilej*podz; dod=(ilej+1)*podz-1; if (ilej==ilen-1) dod=n-1; for (int i=odd; i<=dod; i++) { licz+=GetTaste(i); maxpretu=max(maxpretu, licz); } ogtu=licz; licz=0; for (int i=dod; i>=odd; i--) { licz+=GetTaste(i); maxsuftu=max(maxsuftu, licz); } licz=0; for (int i=odd; i<=dod; i++) { licz+=GetTaste(i); najw=max(najw, licz); maxogtu=max(maxogtu, ogtu-licz+najw); } PutLL(0, maxogtu); PutLL(0, maxpretu); PutLL(0, maxsuftu); PutLL(0, ogtu); Send(0); if (ilej) { return 0; } for (int i=0; i<ilen; i++) { Receive(i); wynog.push_back(GetLL(i)); wynpre.push_back(GetLL(i)); wynsuf.push_back(GetLL(i)); og.push_back(GetLL(i)); } for (int i=0; i<ilen; i++) { for (int j=i; j<ilen; j++) { aktu=0; for (int l=0; l<ilen; l++) { if (l<i || l>j) { aktu+=og[l]; continue; } if (l==i && l==j) { aktu+=wynog[l]; continue; } if (l==i) { aktu+=wynpre[l]; continue; } if (l==j) { aktu+=wynsuf[l]; continue; } } wyn=max(wyn, aktu); } } printf("%lld\n", wyn); return 0; } |