#include <cstdio> #include <algorithm> #include "krazki.h" #include "message.h" using namespace std; typedef long long LL; LL disc[10000000]; LL pipe[10000000]; void convexify(int pipes, int discs) { for(int i = 1; i < pipes; i++) pipe[i] = min(pipe[i-1], pipe[i]); for(int i = 1; i < discs; i++) disc[i] = max(disc[i-1], disc[i]); } void brut(int pipes, int discs) { for(int i = 0; i < pipes; i++) pipe[i] = HoleDiameter(i+1); for(int i = 0; i < discs; i++) disc[i] = DiscDiameter(i+1); convexify(pipes, discs); int cnt = pipes; for(int i = 0; i < discs; i++) { cnt--; while(cnt >= 0 && pipe[cnt] < disc[i]) cnt--; } if(cnt < 0) printf("0"); else printf("%i", cnt+1); } int main() { int node_id = MyNodeId(); int nodes = NumberOfNodes(); int pipes = PipeHeight(); int discs = NumberOfDiscs(); if(discs > pipes) { printf("0"); return 0; } if(node_id == 0) brut(pipes, discs); }
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 | #include <cstdio> #include <algorithm> #include "krazki.h" #include "message.h" using namespace std; typedef long long LL; LL disc[10000000]; LL pipe[10000000]; void convexify(int pipes, int discs) { for(int i = 1; i < pipes; i++) pipe[i] = min(pipe[i-1], pipe[i]); for(int i = 1; i < discs; i++) disc[i] = max(disc[i-1], disc[i]); } void brut(int pipes, int discs) { for(int i = 0; i < pipes; i++) pipe[i] = HoleDiameter(i+1); for(int i = 0; i < discs; i++) disc[i] = DiscDiameter(i+1); convexify(pipes, discs); int cnt = pipes; for(int i = 0; i < discs; i++) { cnt--; while(cnt >= 0 && pipe[cnt] < disc[i]) cnt--; } if(cnt < 0) printf("0"); else printf("%i", cnt+1); } int main() { int node_id = MyNodeId(); int nodes = NumberOfNodes(); int pipes = PipeHeight(); int discs = NumberOfDiscs(); if(discs > pipes) { printf("0"); return 0; } if(node_id == 0) brut(pipes, discs); } |