// Przemysław Szpakowicz #include <bits/stdc++.h> #include "krazki.h" #include "message.h" #define METAFOR(x, a, b) for(x = a; x <= b; ++x) #define MIN(a, b) (a < b ? a : b) #define MINIMUS(a, b) a = MIN(a, b) const int MaxPipeHeight = 100000001; int pipeHeight; int discsAmount; long long diameters[MaxPipeHeight]; int main() { pipeHeight = PipeHeight(); discsAmount = NumberOfDiscs(); int holeIndex; diameters[0] = INT_MAX; METAFOR(holeIndex, 1, pipeHeight) diameters[holeIndex] = HoleDiameter(holeIndex); METAFOR(holeIndex, 1, pipeHeight) MINIMUS(diameters[holeIndex], diameters[holeIndex - 1]); holeIndex = pipeHeight; int discIndex; long long diameter; METAFOR(discIndex, 1, discsAmount) { diameter = DiscDiameter(discIndex); while(holeIndex > 0 && diameters[holeIndex] < diameter) --holeIndex; if(discIndex < discsAmount && holeIndex > 0) --holeIndex; } printf("%d\n", holeIndex); }
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 | // Przemysław Szpakowicz #include <bits/stdc++.h> #include "krazki.h" #include "message.h" #define METAFOR(x, a, b) for(x = a; x <= b; ++x) #define MIN(a, b) (a < b ? a : b) #define MINIMUS(a, b) a = MIN(a, b) const int MaxPipeHeight = 100000001; int pipeHeight; int discsAmount; long long diameters[MaxPipeHeight]; int main() { pipeHeight = PipeHeight(); discsAmount = NumberOfDiscs(); int holeIndex; diameters[0] = INT_MAX; METAFOR(holeIndex, 1, pipeHeight) diameters[holeIndex] = HoleDiameter(holeIndex); METAFOR(holeIndex, 1, pipeHeight) MINIMUS(diameters[holeIndex], diameters[holeIndex - 1]); holeIndex = pipeHeight; int discIndex; long long diameter; METAFOR(discIndex, 1, discsAmount) { diameter = DiscDiameter(discIndex); while(holeIndex > 0 && diameters[holeIndex] < diameter) --holeIndex; if(discIndex < discsAmount && holeIndex > 0) --holeIndex; } printf("%d\n", holeIndex); } |