#include <bits/stdc++.h> #include <sys/time.h> #define ST first #define ND second #define pb push_back #define int long long #define rep(i, a, n) for (int i = a; i <= n; i++) #define per(i, a, n) for (int i = a; i >= n; i--) #define SZ(x) ((int)x.size()) #define ALL(x) (x.begin(), x.end()) #define pii pair <int, int> #define ll long long #define LD long double #define maxn 1000005 using namespace std; int n, t[maxn], ans, siz[maxn], x, liczek, wiel[maxn], dt, maxi[maxn], roz2; int roz, ost; int jw(int x) { int odp = 0; while(x>0) { odp++; x/=10; } return odp; } main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n; rep(i, 1, n) { cin>>t[i]; siz[i]=jw(t[i]); } wiel[0]=1; maxi[0]=0; rep(i, 1, 17) { wiel[i]=wiel[i-1]*10; maxi[i]=maxi[i-1]*10+9; } dt = siz[1]; ost = t[1]; rep(i, 2, n) { if (dt>=15) { roz = 15 - siz[i]; if (t[i]*wiel[roz]+maxi[roz]<ost) { dt++; ost = t[i]*wiel[roz]; } else if (t[i]*wiel[roz]<ost) { ost++; } else ost = t[i]*wiel[roz]; //ost = t[i]*wiel[roz]; ans+=dt-siz[i]; } else { roz = dt-siz[i]; if (roz>=0) { if (t[i]*wiel[roz]>ost) { ost = t[i]*wiel[roz]; } else if (t[i]*wiel[roz]+maxi[roz]>ost) { ost++; } else { dt++; ost = t[i]*wiel[roz+1]; } } else { dt = siz[i]; ost = t[i]; } ans+=dt-siz[i]; } } cout<<ans; } /* if ((dt-siz[t[i]])>=0) { if ((dt-siz[t[i]])*t[i]<=t[i-1]*wiel[dt-siz[t[i-1]]]+liczek) dt++, liczek = 0; else liczek = (dt-siz[t[i]])*t[i]-t[i-1]*wiel[dt-siz[t[i-1]]]+liczek; } else dt = siz[t[i]]; if (wiel[roz]*t[i]+maxi[roz]>t[i-1]*wiel[dt-siz[t[i-1]]]+liczek) liczek = if (t[i]*wiel[roz]>ost) { ost = t[i]*wiel[roz]; dt++; } else if (t[i]*wiel[roz]+maxi[roz]>ost) { ost++; dt++; } */
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 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | #include <bits/stdc++.h> #include <sys/time.h> #define ST first #define ND second #define pb push_back #define int long long #define rep(i, a, n) for (int i = a; i <= n; i++) #define per(i, a, n) for (int i = a; i >= n; i--) #define SZ(x) ((int)x.size()) #define ALL(x) (x.begin(), x.end()) #define pii pair <int, int> #define ll long long #define LD long double #define maxn 1000005 using namespace std; int n, t[maxn], ans, siz[maxn], x, liczek, wiel[maxn], dt, maxi[maxn], roz2; int roz, ost; int jw(int x) { int odp = 0; while(x>0) { odp++; x/=10; } return odp; } main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n; rep(i, 1, n) { cin>>t[i]; siz[i]=jw(t[i]); } wiel[0]=1; maxi[0]=0; rep(i, 1, 17) { wiel[i]=wiel[i-1]*10; maxi[i]=maxi[i-1]*10+9; } dt = siz[1]; ost = t[1]; rep(i, 2, n) { if (dt>=15) { roz = 15 - siz[i]; if (t[i]*wiel[roz]+maxi[roz]<ost) { dt++; ost = t[i]*wiel[roz]; } else if (t[i]*wiel[roz]<ost) { ost++; } else ost = t[i]*wiel[roz]; //ost = t[i]*wiel[roz]; ans+=dt-siz[i]; } else { roz = dt-siz[i]; if (roz>=0) { if (t[i]*wiel[roz]>ost) { ost = t[i]*wiel[roz]; } else if (t[i]*wiel[roz]+maxi[roz]>ost) { ost++; } else { dt++; ost = t[i]*wiel[roz+1]; } } else { dt = siz[i]; ost = t[i]; } ans+=dt-siz[i]; } } cout<<ans; } /* if ((dt-siz[t[i]])>=0) { if ((dt-siz[t[i]])*t[i]<=t[i-1]*wiel[dt-siz[t[i-1]]]+liczek) dt++, liczek = 0; else liczek = (dt-siz[t[i]])*t[i]-t[i-1]*wiel[dt-siz[t[i-1]]]+liczek; } else dt = siz[t[i]]; if (wiel[roz]*t[i]+maxi[roz]>t[i-1]*wiel[dt-siz[t[i-1]]]+liczek) liczek = if (t[i]*wiel[roz]>ost) { ost = t[i]*wiel[roz]; dt++; } else if (t[i]*wiel[roz]+maxi[roz]>ost) { ost++; dt++; } */ |