#include<bits/stdc++.h>
using namespace std;
#define MX_N 200000
typedef long long LL;
#define PLI pair<LL,int>
#define st first
#define nd second
int n, result;
int tab[MX_N+5];
int check( long long x )
{
int ans=0;
long long d=10;
while( x!=0 )
{
x/=d;
d*=10;
ans++;
}
return ans;
}
PLI p;
void solve( )
{
for( int i=0; i<n; i++ )
{
long long nxt=tab[i];
int am=check( tab[i] ), am2=p.nd;
if( nxt<=p.st )
{
if( am==p.nd )
{
result++;
nxt*=10;
am2++;
}
if( p.st/pow(10,p.nd-am)>nxt )//
{
result+=p.nd-am+1;
nxt*=pow(10,p.nd-am+1);
am2++;
}
else
{
int m=pow(10,p.nd-am);
if( p.st%m+1<m )
{
result+=p.nd-am;
nxt*=m;
nxt+=p.st%m+1;
}
else
{
result+=p.nd-am+1;
nxt*=pow(10,p.nd-am+1);
am2++;
}
}
}
p.st=nxt;
p.nd=am2;
}
}
int main( )
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>n;
for( int i=0; i<n; i++ )
cin>>tab[i];
solve();
cout<<result<<"\n";
}
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 | #include<bits/stdc++.h> using namespace std; #define MX_N 200000 typedef long long LL; #define PLI pair<LL,int> #define st first #define nd second int n, result; int tab[MX_N+5]; int check( long long x ) { int ans=0; long long d=10; while( x!=0 ) { x/=d; d*=10; ans++; } return ans; } PLI p; void solve( ) { for( int i=0; i<n; i++ ) { long long nxt=tab[i]; int am=check( tab[i] ), am2=p.nd; if( nxt<=p.st ) { if( am==p.nd ) { result++; nxt*=10; am2++; } if( p.st/pow(10,p.nd-am)>nxt )// { result+=p.nd-am+1; nxt*=pow(10,p.nd-am+1); am2++; } else { int m=pow(10,p.nd-am); if( p.st%m+1<m ) { result+=p.nd-am; nxt*=m; nxt+=p.st%m+1; } else { result+=p.nd-am+1; nxt*=pow(10,p.nd-am+1); am2++; } } } p.st=nxt; p.nd=am2; } } int main( ) { ios_base::sync_with_stdio(0); cin.tie(0); cin>>n; for( int i=0; i<n; i++ ) cin>>tab[i]; solve(); cout<<result<<"\n"; } |
English