#include <bits/stdc++.h> #include "krazki.h" #include "message.h" using namespace std; typedef long long int LL; const int N = 2e7 + 7; /*int H[] = {5, 6, 4, 3, 6, 2, 3}; int D[] = {3, 2, 5}; int MyNodeId(){ return 0; } int NumberOfNodes(){ return 1; } void Send(int a){ } int Receive(int a){ return 0; } int GetInt(int id){ return 0; } LL GetLL(int id){ return 0; } void PutInt(int id, int val){ } void PutLL(int id, LL val){ } int PipeHeight(){ return 7; } int NumberOfDiscs(){ return 3; } LL HoleDiameter(int i){ return H[i - 1]; } LL DiscDiameter(int i){ return D[i - 1]; } */ int n, m; LL mn[N]; int result; int from, to; int Number, MyNode; void get_min(){ from = (1LL * MyNode * n + Number - 1) / (1LL * Number) + 1; to = min(n, (int)((1LL * MyNode * n + n + Number - 1) / (1LL * Number))); mn[0] = HoleDiameter(from); for(int i = from + 1; i <= to; ++i) mn[i - from] = min(mn[i - from - 1], HoleDiameter(i)); LL x = mn[0]; if(MyNode > 0){ int id = Receive(MyNode - 1); x = GetLL(id); } if(to < n){ PutLL(MyNode + 1, min(x, mn[to - from])); Send(MyNode + 1); } for(int i = from; i <= to; ++i) if(mn[i] > x) mn[i] = x; else break; } void cnt_result(){ int i = 1; result = to + 1; if(MyNode + 1 < Number && to < n){ int id = Receive(MyNode + 1); i = GetInt(id); } for(i; i <= m; ++i){ LL x = DiscDiameter(i); result--; while(result >= from && mn[result - from] < x) --result; if(result < from) break; } if(MyNode == 0) printf("%d\n", result); else{ PutInt(MyNode - 1, i); Send(MyNode - 1); } } int main(){ MyNode = MyNodeId(); Number = NumberOfNodes(); n = PipeHeight(); m = NumberOfDiscs(); if(MyNode >= n) return 0; if(Number > n) Number = n; if(m > n){ if(MyNode == 0) puts("0"); return 0; } get_min(); cnt_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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | #include <bits/stdc++.h> #include "krazki.h" #include "message.h" using namespace std; typedef long long int LL; const int N = 2e7 + 7; /*int H[] = {5, 6, 4, 3, 6, 2, 3}; int D[] = {3, 2, 5}; int MyNodeId(){ return 0; } int NumberOfNodes(){ return 1; } void Send(int a){ } int Receive(int a){ return 0; } int GetInt(int id){ return 0; } LL GetLL(int id){ return 0; } void PutInt(int id, int val){ } void PutLL(int id, LL val){ } int PipeHeight(){ return 7; } int NumberOfDiscs(){ return 3; } LL HoleDiameter(int i){ return H[i - 1]; } LL DiscDiameter(int i){ return D[i - 1]; } */ int n, m; LL mn[N]; int result; int from, to; int Number, MyNode; void get_min(){ from = (1LL * MyNode * n + Number - 1) / (1LL * Number) + 1; to = min(n, (int)((1LL * MyNode * n + n + Number - 1) / (1LL * Number))); mn[0] = HoleDiameter(from); for(int i = from + 1; i <= to; ++i) mn[i - from] = min(mn[i - from - 1], HoleDiameter(i)); LL x = mn[0]; if(MyNode > 0){ int id = Receive(MyNode - 1); x = GetLL(id); } if(to < n){ PutLL(MyNode + 1, min(x, mn[to - from])); Send(MyNode + 1); } for(int i = from; i <= to; ++i) if(mn[i] > x) mn[i] = x; else break; } void cnt_result(){ int i = 1; result = to + 1; if(MyNode + 1 < Number && to < n){ int id = Receive(MyNode + 1); i = GetInt(id); } for(i; i <= m; ++i){ LL x = DiscDiameter(i); result--; while(result >= from && mn[result - from] < x) --result; if(result < from) break; } if(MyNode == 0) printf("%d\n", result); else{ PutInt(MyNode - 1, i); Send(MyNode - 1); } } int main(){ MyNode = MyNodeId(); Number = NumberOfNodes(); n = PipeHeight(); m = NumberOfDiscs(); if(MyNode >= n) return 0; if(Number > n) Number = n; if(m > n){ if(MyNode == 0) puts("0"); return 0; } get_min(); cnt_result(); return 0; } |