#include <iostream> #include <vector> using namespace std; const unsigned long long MAKSIMUM = 999999999999999; const unsigned long long MINIMUM = 100000000000000; unsigned long long tab[200007]; unsigned long long pot(unsigned long long x, unsigned long long y) { if(y == 1) return x; if(y%2 == 0) { unsigned long long tmp = pot(x, y/2); return tmp * tmp; } unsigned long long tmp = pot(x, y/2); return tmp * tmp * x; } int main() { ios_base::sync_with_stdio(0); int n; cin>>n; for(int i = 0; i < n ; ++i) { cin>>tab[i]; } unsigned long long wynik = 0; int prev_plus = 0; int plus = 0; for(int i = 1; i < n; ++i) { /* if(tab[i] == tab[i-1]) { ++wynik; tab[i] *= 10; } */ unsigned long long pierwsza = tab[i]; unsigned long long druga = tab[i]; plus = 0; /* if(tab[i] == 40) cout<<wynik<<" "<<prev_plus<<"\n"; */ if(tab[i-1] < tab[i]) continue; while(tab[i-1] > druga && pierwsza < MAKSIMUM) { //cout<<tab[i-1]<<" "<<pierwsza<<" "<<druga<<"tpd\n"; ++plus; pierwsza *= 10; druga *= 10; druga += 9; } /* if(tab[i] == 40) cout<<wynik<<" "<<prev_plus<<" "<<plus<<"pp\n"; */ //jesli nie mamy bardzo duzo zer if(pierwsza < MINIMUM) { if(pierwsza == tab[i-1] && plus == 0) { ++ wynik; ++ plus; pierwsza *=10; tab[i] = pierwsza; } else if(tab[i-1] >= pierwsza && tab[i-1] < druga ) { cout<<"I\n"; wynik += plus; tab[i] = tab[i-1]+1; } else { wynik += plus; tab[i] = pierwsza; } } else//jesli mamy duzo zer dopisanych { if(pierwsza > MAKSIMUM) { pierwsza /= 10; druga /= 10; --plus; } if(tab[i-1] >= pierwsza && tab[i-1] <=druga) { wynik += plus + prev_plus; tab[i] = tab[i-1]; } else if(tab[i-1] > druga) { ++prev_plus; wynik += plus + prev_plus; tab[i] = pierwsza; } else //tab[i-1] < druga { wynik += plus + prev_plus; tab[i] = pierwsza; } } //cout<<tab[i]<<" "<<plus<<" "<<prev_plus<<" "<<wynik<<"tpppw\n"; } /* if(tab[i] < tab[i-1]) { if(tab[i-1]/tab[i] < 10) { tab[i]*=10; ++wynik; continue; } unsigned long long v = 1, o = 0, p = 0; while(tab[i]*v < tab[i-1]) { v *= 10; p *= 10; p += 9; ++o; } //cout<<v<<"v "<<p<<"p\n"; unsigned long long zw =tab[i]*v; //cout<<zw<<"zw1\n"; if(zw == tab[i-1]) { zw++; if((zw / v) > tab[i-1]) { ++o; zw = tab[i]*v*10; } } else { //zw>tab[i-1] p/=10; //cout<<(zw/10)+p<<"zw\n"; if((zw/10)+p > tab[i-1]) { o--; zw= tab[i-1]+1; } }*/ /*++o; long long tmp = pot(10, o); long long zwieksz = tab[i]*v - tab[i-1] + 1; while(zwieksz > tmp) { tmp /= 10; --o; }*/ //wynik+= o; //tab[i]=zw; // cout<<zw<<" "<<o<<"\n"; //} // } /* for(int i = 0 ; i<n; ++i) cout<<tab[i]<<" "; cout<<"\n"; */ cout<<wynik<<"\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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | #include <iostream> #include <vector> using namespace std; const unsigned long long MAKSIMUM = 999999999999999; const unsigned long long MINIMUM = 100000000000000; unsigned long long tab[200007]; unsigned long long pot(unsigned long long x, unsigned long long y) { if(y == 1) return x; if(y%2 == 0) { unsigned long long tmp = pot(x, y/2); return tmp * tmp; } unsigned long long tmp = pot(x, y/2); return tmp * tmp * x; } int main() { ios_base::sync_with_stdio(0); int n; cin>>n; for(int i = 0; i < n ; ++i) { cin>>tab[i]; } unsigned long long wynik = 0; int prev_plus = 0; int plus = 0; for(int i = 1; i < n; ++i) { /* if(tab[i] == tab[i-1]) { ++wynik; tab[i] *= 10; } */ unsigned long long pierwsza = tab[i]; unsigned long long druga = tab[i]; plus = 0; /* if(tab[i] == 40) cout<<wynik<<" "<<prev_plus<<"\n"; */ if(tab[i-1] < tab[i]) continue; while(tab[i-1] > druga && pierwsza < MAKSIMUM) { //cout<<tab[i-1]<<" "<<pierwsza<<" "<<druga<<"tpd\n"; ++plus; pierwsza *= 10; druga *= 10; druga += 9; } /* if(tab[i] == 40) cout<<wynik<<" "<<prev_plus<<" "<<plus<<"pp\n"; */ //jesli nie mamy bardzo duzo zer if(pierwsza < MINIMUM) { if(pierwsza == tab[i-1] && plus == 0) { ++ wynik; ++ plus; pierwsza *=10; tab[i] = pierwsza; } else if(tab[i-1] >= pierwsza && tab[i-1] < druga ) { cout<<"I\n"; wynik += plus; tab[i] = tab[i-1]+1; } else { wynik += plus; tab[i] = pierwsza; } } else//jesli mamy duzo zer dopisanych { if(pierwsza > MAKSIMUM) { pierwsza /= 10; druga /= 10; --plus; } if(tab[i-1] >= pierwsza && tab[i-1] <=druga) { wynik += plus + prev_plus; tab[i] = tab[i-1]; } else if(tab[i-1] > druga) { ++prev_plus; wynik += plus + prev_plus; tab[i] = pierwsza; } else //tab[i-1] < druga { wynik += plus + prev_plus; tab[i] = pierwsza; } } //cout<<tab[i]<<" "<<plus<<" "<<prev_plus<<" "<<wynik<<"tpppw\n"; } /* if(tab[i] < tab[i-1]) { if(tab[i-1]/tab[i] < 10) { tab[i]*=10; ++wynik; continue; } unsigned long long v = 1, o = 0, p = 0; while(tab[i]*v < tab[i-1]) { v *= 10; p *= 10; p += 9; ++o; } //cout<<v<<"v "<<p<<"p\n"; unsigned long long zw =tab[i]*v; //cout<<zw<<"zw1\n"; if(zw == tab[i-1]) { zw++; if((zw / v) > tab[i-1]) { ++o; zw = tab[i]*v*10; } } else { //zw>tab[i-1] p/=10; //cout<<(zw/10)+p<<"zw\n"; if((zw/10)+p > tab[i-1]) { o--; zw= tab[i-1]+1; } }*/ /*++o; long long tmp = pot(10, o); long long zwieksz = tab[i]*v - tab[i-1] + 1; while(zwieksz > tmp) { tmp /= 10; --o; }*/ //wynik+= o; //tab[i]=zw; // cout<<zw<<" "<<o<<"\n"; //} // } /* for(int i = 0 ; i<n; ++i) cout<<tab[i]<<" "; cout<<"\n"; */ cout<<wynik<<"\n"; } |