// Zadanie: Krazki [B] // Autor: Arkadiusz Roussau #include <algorithm> #include <iostream> #include "message.h" #include "krazki.h" using namespace std; const long long MAX_N = 10000001; long long TAB[MAX_N], pipe_height, number_of_discs, last_disc, tmp; int main() { ios_base::sync_with_stdio(0); if (MyNodeId() == 0) { pipe_height = PipeHeight(); number_of_discs = NumberOfDiscs(); TAB[1] = HoleDiameter(1); for (int i = 2; i <= pipe_height; ++i) { TAB[i] = min(TAB[i - 1], HoleDiameter(i)); } last_disc = pipe_height + 1; for (int i = 1; i <= number_of_discs; ++i) { tmp = last_disc - 1; while ((tmp > 0) && (TAB[tmp] < DiscDiameter(i))) { tmp--; } last_disc = tmp; if (last_disc == 0) { break; } } cout << last_disc << "\n"; } 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 | // Zadanie: Krazki [B] // Autor: Arkadiusz Roussau #include <algorithm> #include <iostream> #include "message.h" #include "krazki.h" using namespace std; const long long MAX_N = 10000001; long long TAB[MAX_N], pipe_height, number_of_discs, last_disc, tmp; int main() { ios_base::sync_with_stdio(0); if (MyNodeId() == 0) { pipe_height = PipeHeight(); number_of_discs = NumberOfDiscs(); TAB[1] = HoleDiameter(1); for (int i = 2; i <= pipe_height; ++i) { TAB[i] = min(TAB[i - 1], HoleDiameter(i)); } last_disc = pipe_height + 1; for (int i = 1; i <= number_of_discs; ++i) { tmp = last_disc - 1; while ((tmp > 0) && (TAB[tmp] < DiscDiameter(i))) { tmp--; } last_disc = tmp; if (last_disc == 0) { break; } } cout << last_disc << "\n"; } return 0; } |