#include <bits/stdc++.h> using namespace std; pair < long long, long long > zn_d(long long x, long long y){ long long wyn = 1, c = 0; while(x > y*wyn){ wyn*=10; c++; } return {wyn, c}; } long long znajdz(long long x, long long y, long long p){ //printf("%d\n",p); while(p/10 > 0){ p/=10; //printf(">>>%d %d\n",y+p-1, p); while(y+p-1 < x){ y+=p; } //printf("oo %d\n",y); } return y; } int main(){ int n; long long ost=0, ans=0; scanf("%d",&n); for(int i=0; i<n; i++){ long long x; ost++; scanf("%lld",&x); auto pot = zn_d(ost, x); //printf("%d %d %d\n",pot.first, pot.second, x*(pot.first/10)+(pot.first/10)-1 >= ost ); if(x*(pot.first/10)+(pot.first/10)-1 >= ost){ ans+=pot.second-1; //printf(">>%d\n",ost); ost = znajdz(ost, x*(pot.first/10), pot.first/10); } else{ ans+=pot.second; ost = x*pot.first; } //printf(">%d\n",pot.second); //ost = x; } printf("%lld\n",ans); 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 | #include <bits/stdc++.h> using namespace std; pair < long long, long long > zn_d(long long x, long long y){ long long wyn = 1, c = 0; while(x > y*wyn){ wyn*=10; c++; } return {wyn, c}; } long long znajdz(long long x, long long y, long long p){ //printf("%d\n",p); while(p/10 > 0){ p/=10; //printf(">>>%d %d\n",y+p-1, p); while(y+p-1 < x){ y+=p; } //printf("oo %d\n",y); } return y; } int main(){ int n; long long ost=0, ans=0; scanf("%d",&n); for(int i=0; i<n; i++){ long long x; ost++; scanf("%lld",&x); auto pot = zn_d(ost, x); //printf("%d %d %d\n",pot.first, pot.second, x*(pot.first/10)+(pot.first/10)-1 >= ost ); if(x*(pot.first/10)+(pot.first/10)-1 >= ost){ ans+=pot.second-1; //printf(">>%d\n",ost); ost = znajdz(ost, x*(pot.first/10), pot.first/10); } else{ ans+=pot.second; ost = x*pot.first; } //printf(">%d\n",pot.second); //ost = x; } printf("%lld\n",ans); return 0; } |