#include <bits/stdc++.h> #define deb(x) #define fr front #define pob pop_back #define last(V) V[V.size()-1] #define sp <<" "<< #define ent <<"\n" #define mp make_pair #define pb push_back #define pu push #define st first #define e second.st #define ad second.second #define VI vector<int> #define VII vector<pair<int,int> > #define inf 1000000000 #define uns unsigned #define ll long long #define ld long double #define uint unsigned int using namespace std; const int MN=0; ll t[15]; vector <pair<ll,pair<ll,ll> > > V; int main() { ios_base::sync_with_stdio(0); cin.tie(0); t[1]=10; for(int i=2;i<15;i++) t[i]=t[i-1]*10; ll n,x,odp=0,ca=1; cin>>n; for(int i=0;i<n;i++) { cin>>x; V.pb({x,{0,0}}); // V.pb({1,{0,0}}); } for(int i=1;i<n;i++) { if(V[i].e<V[i-1].e) { // cout<<"case :" sp 1 ent; odp+=V[i-1].e-V[i].e; V[i].ad+=V[i-1].e-V[i].e; V[i].e=V[i-1].e; } while(V[i].st<V[i-1].st && V[i].e==V[i-1].e) { // cout<<"case :" sp 2 ent; odp++; V[i].ad++; V[i].st*=10; if(inf<V[i].st) { V[i].e++; V[i].st/=10; } } // cout<<"elo" sp i sp ca sp V[i].st sp V[i-1].st sp V[i].e sp V[i-1].e ent; if(V[i].st==V[i-1].st && V[i].e==V[i-1].e){ if(V[i].ad==0) { // cout<<"case :" sp 3 ent; odp++; V[i].ad++; V[i].st*=10; if(inf<V[i].st) { V[i].e++; V[i].st/=10; } }else{ // cout<<"case :" sp 4 ent; ca++; if(ca<=t[V[i].ad]) { //ok, miescm sie }else{ ca=1; odp++; V[i].ad++; V[i].st*=10; if(inf<V[i].st) { V[i].e++; V[i].st/=10; } } } }else{ // cout<<"case :" sp 5 ent; ca=1; } } /* for(int i=0;i<n;i++) { cout<<i sp V[i].st sp V[i].e sp"ayy lmao" sp V[i].ad ent; } */ cout<< odp ent; 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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | #include <bits/stdc++.h> #define deb(x) #define fr front #define pob pop_back #define last(V) V[V.size()-1] #define sp <<" "<< #define ent <<"\n" #define mp make_pair #define pb push_back #define pu push #define st first #define e second.st #define ad second.second #define VI vector<int> #define VII vector<pair<int,int> > #define inf 1000000000 #define uns unsigned #define ll long long #define ld long double #define uint unsigned int using namespace std; const int MN=0; ll t[15]; vector <pair<ll,pair<ll,ll> > > V; int main() { ios_base::sync_with_stdio(0); cin.tie(0); t[1]=10; for(int i=2;i<15;i++) t[i]=t[i-1]*10; ll n,x,odp=0,ca=1; cin>>n; for(int i=0;i<n;i++) { cin>>x; V.pb({x,{0,0}}); // V.pb({1,{0,0}}); } for(int i=1;i<n;i++) { if(V[i].e<V[i-1].e) { // cout<<"case :" sp 1 ent; odp+=V[i-1].e-V[i].e; V[i].ad+=V[i-1].e-V[i].e; V[i].e=V[i-1].e; } while(V[i].st<V[i-1].st && V[i].e==V[i-1].e) { // cout<<"case :" sp 2 ent; odp++; V[i].ad++; V[i].st*=10; if(inf<V[i].st) { V[i].e++; V[i].st/=10; } } // cout<<"elo" sp i sp ca sp V[i].st sp V[i-1].st sp V[i].e sp V[i-1].e ent; if(V[i].st==V[i-1].st && V[i].e==V[i-1].e){ if(V[i].ad==0) { // cout<<"case :" sp 3 ent; odp++; V[i].ad++; V[i].st*=10; if(inf<V[i].st) { V[i].e++; V[i].st/=10; } }else{ // cout<<"case :" sp 4 ent; ca++; if(ca<=t[V[i].ad]) { //ok, miescm sie }else{ ca=1; odp++; V[i].ad++; V[i].st*=10; if(inf<V[i].st) { V[i].e++; V[i].st/=10; } } } }else{ // cout<<"case :" sp 5 ent; ca=1; } } /* for(int i=0;i<n;i++) { cout<<i sp V[i].st sp V[i].e sp"ayy lmao" sp V[i].ad ent; } */ cout<< odp ent; return 0; } |