#include <bits/stdc++.h> #define fi first #define se second #define ll long long #define inf (1<<30); #define pi pair <int,int> #define pl pair <long long, long long> #define ld long double #define pb push_back #define lt(n, d, res, i) if(n < d) { res=i; } using namespace std; const int MAXN = 200002; const int MAXD = 12; ll D[MAXD]; int digits(ll n) { int res = 1000; lt(n, 10000000000, res, 10) lt(n, 1000000000, res, 9) lt(n, 100000000, res, 8) lt(n, 10000000, res, 7) lt(n, 1000000, res, 6) lt(n, 100000, res, 5) lt(n, 10000, res, 4) lt(n, 1000, res, 3) lt(n, 100, res, 2) lt(n, 10, res, 1) lt(n, 1, res, 0) return res; } void pre() { D[0] = 1; for(int i=1; i<MAXD; i++) { D[i] = D[i-1]*10; } } int main() { ios_base::sync_with_stdio(0); pre(); int n; cin>>n; ll prev = -1; ll a; int prev_digits = 0; int a_digits; ll res = 0; for(int i=0; i<n; i++) { cin>>a; a_digits = digits(a); //cout<<a<<" -> "; if(a <= prev) { int l = prev_digits - a_digits; ll b = prev / D[l]; // 1 ll a_prim = prev + 1; // 11 ll b_prim = a_prim / D[l]; // 1 if(b > a || b_prim != a) { a = a*D[l]; a_digits = a_digits+l; res += l; if(a <= prev) { a *= 10; a_digits++; res++; } } else { a = a_prim; a_digits = a_digits + l; res += l; } } //cout<<a<<endl; prev = a; prev_digits = a_digits; } cout<<res<<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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | #include <bits/stdc++.h> #define fi first #define se second #define ll long long #define inf (1<<30); #define pi pair <int,int> #define pl pair <long long, long long> #define ld long double #define pb push_back #define lt(n, d, res, i) if(n < d) { res=i; } using namespace std; const int MAXN = 200002; const int MAXD = 12; ll D[MAXD]; int digits(ll n) { int res = 1000; lt(n, 10000000000, res, 10) lt(n, 1000000000, res, 9) lt(n, 100000000, res, 8) lt(n, 10000000, res, 7) lt(n, 1000000, res, 6) lt(n, 100000, res, 5) lt(n, 10000, res, 4) lt(n, 1000, res, 3) lt(n, 100, res, 2) lt(n, 10, res, 1) lt(n, 1, res, 0) return res; } void pre() { D[0] = 1; for(int i=1; i<MAXD; i++) { D[i] = D[i-1]*10; } } int main() { ios_base::sync_with_stdio(0); pre(); int n; cin>>n; ll prev = -1; ll a; int prev_digits = 0; int a_digits; ll res = 0; for(int i=0; i<n; i++) { cin>>a; a_digits = digits(a); //cout<<a<<" -> "; if(a <= prev) { int l = prev_digits - a_digits; ll b = prev / D[l]; // 1 ll a_prim = prev + 1; // 11 ll b_prim = a_prim / D[l]; // 1 if(b > a || b_prim != a) { a = a*D[l]; a_digits = a_digits+l; res += l; if(a <= prev) { a *= 10; a_digits++; res++; } } else { a = a_prim; a_digits = a_digits + l; res += l; } } //cout<<a<<endl; prev = a; prev_digits = a_digits; } cout<<res<<endl; return 0; } |