#include <cstdio> struct Number { Number(long long a) { pow10 = 0; prefix = a; while (10 * prefix < 10000000000LL) { prefix *= 10; --pow10; } } long long prefix; int pow10; }; int main() { int n; long long result = 0, tmp; scanf("%d", &n); scanf("%lld", &tmp); Number previous(tmp); for (int i = 1; i < n; ++i) { scanf("%lld", &tmp); Number current(tmp); long long local_result = 0; if (current.pow10 < previous.pow10) { local_result = previous.pow10 - current.pow10; current.pow10 = previous.pow10; } if (current.pow10 == previous.pow10 && current.prefix <= previous.prefix) { long long tz = previous.prefix; long long rem = 0; long long pw = 1; while (tz > tmp) { rem += (tz % 10) * pw; pw *= 10; tz /= 10; } if (tz == tmp) { long long px = current.pow10; long long add = 1; while (px < 0) { ++px; add *= 10; } rem += add; if (rem < pw) { current.prefix += rem; } else { ++local_result; ++current.pow10; } } else { ++local_result; ++current.pow10; } } previous = current; result += local_result; } printf("%lld\n", result); 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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | #include <cstdio> struct Number { Number(long long a) { pow10 = 0; prefix = a; while (10 * prefix < 10000000000LL) { prefix *= 10; --pow10; } } long long prefix; int pow10; }; int main() { int n; long long result = 0, tmp; scanf("%d", &n); scanf("%lld", &tmp); Number previous(tmp); for (int i = 1; i < n; ++i) { scanf("%lld", &tmp); Number current(tmp); long long local_result = 0; if (current.pow10 < previous.pow10) { local_result = previous.pow10 - current.pow10; current.pow10 = previous.pow10; } if (current.pow10 == previous.pow10 && current.prefix <= previous.prefix) { long long tz = previous.prefix; long long rem = 0; long long pw = 1; while (tz > tmp) { rem += (tz % 10) * pw; pw *= 10; tz /= 10; } if (tz == tmp) { long long px = current.pow10; long long add = 1; while (px < 0) { ++px; add *= 10; } rem += add; if (rem < pw) { current.prefix += rem; } else { ++local_result; ++current.pow10; } } else { ++local_result; ++current.pow10; } } previous = current; result += local_result; } printf("%lld\n", result); return 0; } |