#include<cstdio> int p10[]={1,10,100,1000,10000,100000,1000000,10000000}; typedef long long LL; LL res; LL atleast(LL a,int b) { LL aa=a; for(;a<b;++res) a=10*a+9,aa=10*aa; if(aa<=b) aa=b; return aa; } struct bignum { int m; int c; int p; bignum(const int a): m(a),c(0),p(0){} void operator ++() { ++p; if(c<8 && p>=p10[c]) p-=p10[c],++m; if(m>1000000000) m/=10,++c; } void next(int a) { LL w=atleast(a,m); if(w>m) { if(w>1000000000) m=w/10,p=0,++c,--res; else m=w,p=0; } res+=c; // printf("%d %d %d %lld\n",m,c,p,res); } }; int main() { int n,b; scanf("%d%d",&n,&b); for(bignum x(b);--n;) { ++x; scanf("%d",&b); x.next(b); } printf("%lld",res); 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 | #include<cstdio> int p10[]={1,10,100,1000,10000,100000,1000000,10000000}; typedef long long LL; LL res; LL atleast(LL a,int b) { LL aa=a; for(;a<b;++res) a=10*a+9,aa=10*aa; if(aa<=b) aa=b; return aa; } struct bignum { int m; int c; int p; bignum(const int a): m(a),c(0),p(0){} void operator ++() { ++p; if(c<8 && p>=p10[c]) p-=p10[c],++m; if(m>1000000000) m/=10,++c; } void next(int a) { LL w=atleast(a,m); if(w>m) { if(w>1000000000) m=w/10,p=0,++c,--res; else m=w,p=0; } res+=c; // printf("%d %d %d %lld\n",m,c,p,res); } }; int main() { int n,b; scanf("%d%d",&n,&b); for(bignum x(b);--n;) { ++x; scanf("%d",&b); x.next(b); } printf("%lld",res); return 0; } |