#include <iostream> using namespace std; unsigned long long ddd(unsigned long long a) { unsigned long long res = 0; while (a > 0) { res++; a = a/10; } return res; } unsigned long long mmm(unsigned long long a) { unsigned long long res = 1; while (a+1 > 0) { res = res*10; a--; } return res; } int main() { ios_base::sync_with_stdio(false); int N; cin >> N; unsigned long long sum = 0; long long prev = -1; long long dd = 0; for (int i = 0; i < N; i++) { long long a; cin >> a; long long aa = a; if (prev < 1e15) { long long d = 1; prev++; while (a*10<prev) { a = a*10; d = d*10; sum++; } if (a < prev) { if (a+d-1 < prev || a == aa) { a = a*10; sum++; } else { a = prev; } } prev = a; } else { long long dprev = ddd(prev); if (dd == 0) dd = dprev; long long da = ddd(a); long long cutprev = prev/mmm(dprev-da-1); if (a < cutprev) dd++; if (a != cutprev) prev = a*mmm(15-da); sum += dd-da; } } cout << sum << endl; 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 67 68 69 70 71 72 73 74 75 76 | #include <iostream> using namespace std; unsigned long long ddd(unsigned long long a) { unsigned long long res = 0; while (a > 0) { res++; a = a/10; } return res; } unsigned long long mmm(unsigned long long a) { unsigned long long res = 1; while (a+1 > 0) { res = res*10; a--; } return res; } int main() { ios_base::sync_with_stdio(false); int N; cin >> N; unsigned long long sum = 0; long long prev = -1; long long dd = 0; for (int i = 0; i < N; i++) { long long a; cin >> a; long long aa = a; if (prev < 1e15) { long long d = 1; prev++; while (a*10<prev) { a = a*10; d = d*10; sum++; } if (a < prev) { if (a+d-1 < prev || a == aa) { a = a*10; sum++; } else { a = prev; } } prev = a; } else { long long dprev = ddd(prev); if (dd == 0) dd = dprev; long long da = ddd(a); long long cutprev = prev/mmm(dprev-da-1); if (a < cutprev) dd++; if (a != cutprev) prev = a*mmm(15-da); sum += dd-da; } } cout << sum << endl; return 0; } |