#include <iostream>
#include <cmath>
#include <algorithm>
int len(long long x) {
if (x < 10) return 1;
else return 1 + len(x/10);
}
long long trans(long long a, int x) {
if (x == 0) return a; else return 10 * trans(a, x- 1);
}
long long adjust(long long a, long long b) {
return trans(a, len(b) - len(a));
}
int main() {
std::ios::sync_with_stdio(false);
int n;
std::cin >> n;
long long c = 0;
long long sum = 0;
long long a;
long long current_length = 0;
while (n--) {
std::cin >> a;
if (len(a) <= len(c) + current_length) {
long long x = len(c) - len(a);
long long low = adjust(a, c);
if (c - low + 1LL >= trans(1, x)) {
low *= 10;
x++;
}
sum += x + current_length;
a = low + std::max(0LL, c - low + 1);
if (a >= trans(1, 15)) {
a /= 10;
current_length++;
}
}
c = a;
}
std::cout << sum;
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 | #include <iostream> #include <cmath> #include <algorithm> int len(long long x) { if (x < 10) return 1; else return 1 + len(x/10); } long long trans(long long a, int x) { if (x == 0) return a; else return 10 * trans(a, x- 1); } long long adjust(long long a, long long b) { return trans(a, len(b) - len(a)); } int main() { std::ios::sync_with_stdio(false); int n; std::cin >> n; long long c = 0; long long sum = 0; long long a; long long current_length = 0; while (n--) { std::cin >> a; if (len(a) <= len(c) + current_length) { long long x = len(c) - len(a); long long low = adjust(a, c); if (c - low + 1LL >= trans(1, x)) { low *= 10; x++; } sum += x + current_length; a = low + std::max(0LL, c - low + 1); if (a >= trans(1, 15)) { a /= 10; current_length++; } } c = a; } std::cout << sum; return 0; } |
English