#include <bits/stdc++.h> using namespace std; const int maxn = 3e5; typedef long long ll; typedef pair<int, int> Pii; typedef vector<Pii> vpii; typedef vector<int> vi; typedef vector<ll> vll; #define pb push_back #define fst first #define snd second int n; const ll dz8 = 10000ll * 10000ll; const ll dz16 = dz8 * dz8; const ll dz17 = 10 * dz16; ll dziew[40]; void init() { dziew[0] = 0; for(int i = 1; i < 30; ++i) dziew[i] = dziew[i-1] * 10 + 9; } int main() { init(); scanf("%d", &n); ll res = 0; ll pop = 0; ll zer = 0; for(int i = 0; i < n; ++i) { ll a; scanf("%lld", &a); ll dod = 0; while(a + dziew[dod] <= pop) { ++dod; a *= 10; } if(a <= pop) { a = pop + 1; } if(a >= dz17) { a /= 10; --dod; ++zer; } res += zer + dod; pop = a; } printf("%lld\n", res); }
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 | #include <bits/stdc++.h> using namespace std; const int maxn = 3e5; typedef long long ll; typedef pair<int, int> Pii; typedef vector<Pii> vpii; typedef vector<int> vi; typedef vector<ll> vll; #define pb push_back #define fst first #define snd second int n; const ll dz8 = 10000ll * 10000ll; const ll dz16 = dz8 * dz8; const ll dz17 = 10 * dz16; ll dziew[40]; void init() { dziew[0] = 0; for(int i = 1; i < 30; ++i) dziew[i] = dziew[i-1] * 10 + 9; } int main() { init(); scanf("%d", &n); ll res = 0; ll pop = 0; ll zer = 0; for(int i = 0; i < n; ++i) { ll a; scanf("%lld", &a); ll dod = 0; while(a + dziew[dod] <= pop) { ++dod; a *= 10; } if(a <= pop) { a = pop + 1; } if(a >= dz17) { a /= 10; --dod; ++zer; } res += zer + dod; pop = a; } printf("%lld\n", res); } |