#include <iostream>
#include <cmath>
using namespace std;
long long liczby[200000];
long long liczbazer[200000];
long long wynik=0;
long long dodatkowezera=0;
long long howmanynum(long long a) {
long long numa=0;
while(a!=0) {
a = a/10;
numa++;
}
return numa;
}
long long newnumbers(long long a,long long b) {
long long tempb=b,numa,numb;
long long tempa=a;
long long dif=0;
if(a<b) return b;
if(tempa>1000000000000000) {tempa/=10;
dodatkowezera++;}
numa=howmanynum(tempa);
numb=howmanynum(tempb);
// cout <<dodatkowezera<<endl;
tempb = b*pow(10, numa-numb);
dif=tempa-tempb;
if (dif<0) {
wynik += numa-numb+dodatkowezera;
// cout<<wynik<<endl;
return tempb;
}
if(dif==0&&numa-numb==0){
wynik += numa-numb+1+dodatkowezera;
// cout<<"wiekszy"<<wynik<<endl;
return tempb*10;
}
if(howmanynum(dif+1)<=(numa-numb)) {
wynik += numa-numb+dodatkowezera;
// cout<<"mniejszy"<<wynik<<endl;
return tempb+dif+1;
}
else {
wynik += numa-numb+1+dodatkowezera;
// cout<<"wiekszy"<<wynik<<endl;
return tempb*10;
}
}
int main(){
long long n;
cin >> n;
for(long long i =0;i <n ; i++) {
cin >> liczby[i];
// cout<< liczby[i]<<endl;
}
// cout <<endl;
for(long long i= 1; i<n;i++ ) {
liczby[i]=newnumbers(liczby[i-1],liczby[i]);
// cout <<liczby[i]<<endl;
}
// cout << newnumbers(liczby[0],liczby[1]);
cout <<wynik<<endl;
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 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 | #include <iostream> #include <cmath> using namespace std; long long liczby[200000]; long long liczbazer[200000]; long long wynik=0; long long dodatkowezera=0; long long howmanynum(long long a) { long long numa=0; while(a!=0) { a = a/10; numa++; } return numa; } long long newnumbers(long long a,long long b) { long long tempb=b,numa,numb; long long tempa=a; long long dif=0; if(a<b) return b; if(tempa>1000000000000000) {tempa/=10; dodatkowezera++;} numa=howmanynum(tempa); numb=howmanynum(tempb); // cout <<dodatkowezera<<endl; tempb = b*pow(10, numa-numb); dif=tempa-tempb; if (dif<0) { wynik += numa-numb+dodatkowezera; // cout<<wynik<<endl; return tempb; } if(dif==0&&numa-numb==0){ wynik += numa-numb+1+dodatkowezera; // cout<<"wiekszy"<<wynik<<endl; return tempb*10; } if(howmanynum(dif+1)<=(numa-numb)) { wynik += numa-numb+dodatkowezera; // cout<<"mniejszy"<<wynik<<endl; return tempb+dif+1; } else { wynik += numa-numb+1+dodatkowezera; // cout<<"wiekszy"<<wynik<<endl; return tempb*10; } } int main(){ long long n; cin >> n; for(long long i =0;i <n ; i++) { cin >> liczby[i]; // cout<< liczby[i]<<endl; } // cout <<endl; for(long long i= 1; i<n;i++ ) { liczby[i]=newnumbers(liczby[i-1],liczby[i]); // cout <<liczby[i]<<endl; } // cout << newnumbers(liczby[0],liczby[1]); cout <<wynik<<endl; return 0; } |
English