#include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long LL; const LL LIM = 1e16; int l(LL x) { char s[20]; sprintf(s, "%lld", x); return strlen(s); } int main() { int n; scanf("%d", &n); LL r = 0, p = 0, x, y; scanf("%lld", &x); for (int i=1; i<n; ++i) { scanf("%lld", &y); LL nin = 1; for (int j=max(0, l(x)-l(y)); j; --j) y *= 10, nin *= 10, ++r; if (x >= y) { if (x < y+nin-1) y = x+1; else { if (10*y < LIM) y *= 10, ++r; else ++p; } } r += p; x = y; } printf("%lld\n", r); 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 | #include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long LL; const LL LIM = 1e16; int l(LL x) { char s[20]; sprintf(s, "%lld", x); return strlen(s); } int main() { int n; scanf("%d", &n); LL r = 0, p = 0, x, y; scanf("%lld", &x); for (int i=1; i<n; ++i) { scanf("%lld", &y); LL nin = 1; for (int j=max(0, l(x)-l(y)); j; --j) y *= 10, nin *= 10, ++r; if (x >= y) { if (x < y+nin-1) y = x+1; else { if (10*y < LIM) y *= 10, ++r; else ++p; } } r += p; x = y; } printf("%lld\n", r); return 0; } |