#include <cstdio> long long n,k,last=-1,sum=0,dig,lastdig,actdig,digdiff,lastcand,sparezeros; long long MAXL = 100000000000000000L; inline long long digits(long long l){ dig=0; while (l != 0) { dig ++; l /= 10; } return dig; } inline long long trimDigits(long long l,long long ile){ if(ile>0) while(ile--){ l/=10; } return l; } int main(){ scanf("%lld",&n); lastdig=-1; sparezeros=0; while(n--){ scanf("%lld",&k); if(k<=last){ actdig=digits(k); lastcand = last+1; lastdig=digits(lastcand); // if(k != trimDigits(lastcand, lastdig-actdig)){ // printf("xD %lld %lld\n",k,trimDigits(lastcand, lastdig-actdig)); lastcand=k*10; while(lastcand<last){ lastcand*=10; if(lastcand>MAXL){ sparezeros++; lastcand/=10; break; } } } last=lastcand; // printf("xxxxxD %lld +%lld\n",last,(digits(lastcand)-digits(k))); sum += (digits(lastcand)-digits(k)+sparezeros); } else{ last=k; // printf("xxxxXD %lld\n",last); } // printf("%lld",digits(k)); } printf("%lld",sum); }
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 | #include <cstdio> long long n,k,last=-1,sum=0,dig,lastdig,actdig,digdiff,lastcand,sparezeros; long long MAXL = 100000000000000000L; inline long long digits(long long l){ dig=0; while (l != 0) { dig ++; l /= 10; } return dig; } inline long long trimDigits(long long l,long long ile){ if(ile>0) while(ile--){ l/=10; } return l; } int main(){ scanf("%lld",&n); lastdig=-1; sparezeros=0; while(n--){ scanf("%lld",&k); if(k<=last){ actdig=digits(k); lastcand = last+1; lastdig=digits(lastcand); // if(k != trimDigits(lastcand, lastdig-actdig)){ // printf("xD %lld %lld\n",k,trimDigits(lastcand, lastdig-actdig)); lastcand=k*10; while(lastcand<last){ lastcand*=10; if(lastcand>MAXL){ sparezeros++; lastcand/=10; break; } } } last=lastcand; // printf("xxxxxD %lld +%lld\n",last,(digits(lastcand)-digits(k))); sum += (digits(lastcand)-digits(k)+sparezeros); } else{ last=k; // printf("xxxxXD %lld\n",last); } // printf("%lld",digits(k)); } printf("%lld",sum); } |