// Example program #include <iostream> #include <string> #include <math.h> int main() { unsigned long long prev = 0; unsigned long long counter = 0; int n; std::cin >> n; while (n-- > 0) { unsigned long long c; std::cin >> c; if (c <= prev) { auto zc = (int)log10(prev) - (int)log10(c); auto padV = c * (unsigned long long) pow10(zc); if (padV > prev) { prev = padV; counter += zc; } else if (zc > 0 && ( (int)log10(prev - padV + 1)) < zc) { prev = prev + 1; counter += zc; } else { prev = padV * 10; counter += zc + 1; } } else { prev = c; } } std::cout << counter; 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 | // Example program #include <iostream> #include <string> #include <math.h> int main() { unsigned long long prev = 0; unsigned long long counter = 0; int n; std::cin >> n; while (n-- > 0) { unsigned long long c; std::cin >> c; if (c <= prev) { auto zc = (int)log10(prev) - (int)log10(c); auto padV = c * (unsigned long long) pow10(zc); if (padV > prev) { prev = padV; counter += zc; } else if (zc > 0 && ( (int)log10(prev - padV + 1)) < zc) { prev = prev + 1; counter += zc; } else { prev = padV * 10; counter += zc + 1; } } else { prev = c; } } std::cout << counter; return 0; } |