#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <vector>
using std::vector;
int nodeId, nrOfNodes;
int startPipe, endPipe;
int pipe_height, number_of_discs;
#if 0
std::vector<long long int> pipeVal, discs;
void init() {
std::cin >> pipe_height >> number_of_discs;
pipeVal.resize(pipe_height);
for (int i = 0; i < pipe_height; i++) {
std::cin >> pipeVal[i];
}
discs.resize(number_of_discs);
for (int i = 0; i < number_of_discs; i++) {
std::cin >> discs[i];
}
}
long long getPipe(int index) {
return pipeVal[index-1];
}
long long getDisc(int index) {
return discs[index-1];
}
#else
#include "krazki.h"
#include "message.h"
void init() {
pipe_height = PipeHeight();
number_of_discs = NumberOfDiscs();
}
long long getPipe(int index) {
return HoleDiameter(index);
}
long long getDisc(int index) {
return DiscDiameter(index);
}
#endif
vector<long long> prefixMin;
int main() {
init();
if (MyNodeId() != 0)
return 0;
prefixMin.push_back(0);
prefixMin.push_back(getPipe(1));
for(int i = 2; i <= pipe_height; ++i) {
prefixMin.push_back( std::min(prefixMin[i-1], getPipe(i)) );
}
// for(int i = 1; i <= pipe_height; ++i) {
// printf("min[%d] = %d\n", i, prefixMin[i]);
// }
int pos = pipe_height+1;
for(int d = 1; d <= number_of_discs; ++d) {
pos--;
while (pos > 0 && getDisc(d) > prefixMin[pos]) {
pos--;
}
// printf("%d (val = %d) at %d\n", d, getDisc(d), pos);
if (pos == 0) {
printf("0\n");
std::exit(0);
}
}
printf("%d\n", pos);
return EXIT_SUCCESS;
}
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 | #include <cstdlib> #include <cstdio> #include <iostream> #include <vector> using std::vector; int nodeId, nrOfNodes; int startPipe, endPipe; int pipe_height, number_of_discs; #if 0 std::vector<long long int> pipeVal, discs; void init() { std::cin >> pipe_height >> number_of_discs; pipeVal.resize(pipe_height); for (int i = 0; i < pipe_height; i++) { std::cin >> pipeVal[i]; } discs.resize(number_of_discs); for (int i = 0; i < number_of_discs; i++) { std::cin >> discs[i]; } } long long getPipe(int index) { return pipeVal[index-1]; } long long getDisc(int index) { return discs[index-1]; } #else #include "krazki.h" #include "message.h" void init() { pipe_height = PipeHeight(); number_of_discs = NumberOfDiscs(); } long long getPipe(int index) { return HoleDiameter(index); } long long getDisc(int index) { return DiscDiameter(index); } #endif vector<long long> prefixMin; int main() { init(); if (MyNodeId() != 0) return 0; prefixMin.push_back(0); prefixMin.push_back(getPipe(1)); for(int i = 2; i <= pipe_height; ++i) { prefixMin.push_back( std::min(prefixMin[i-1], getPipe(i)) ); } // for(int i = 1; i <= pipe_height; ++i) { // printf("min[%d] = %d\n", i, prefixMin[i]); // } int pos = pipe_height+1; for(int d = 1; d <= number_of_discs; ++d) { pos--; while (pos > 0 && getDisc(d) > prefixMin[pos]) { pos--; } // printf("%d (val = %d) at %d\n", d, getDisc(d), pos); if (pos == 0) { printf("0\n"); std::exit(0); } } printf("%d\n", pos); return EXIT_SUCCESS; } |
English