提交时间:2023-08-14 15:08:59

运行 ID: 98325

#include <iostream> #include <algorithm> #define ll long long using namespace std; const int N = 2e5 + 5; int n; ll a[N], b[N]; int f(ll x) { int ans = 0; while (x) { ans += x % 10; x /= 10; } return ans; } ll read() { char ch = getchar(); ll sum = 0; while (ch < '0' || ch > '9') { ch = getchar(); } while (ch >= '0' && ch <= '9') { sum = (sum << 1) + (sum << 3) + (ch ^ 48); ch = getchar(); } return sum; } int main() { cin >> n; int ans = 0; for (int i = 1; i <= n; ++ i) { a[i] = read(); ans += f(a[i]); } ans *= 2 * n; int sum = 0; for (ll i = 10; i <= 1e15; i *= 10) { for (int j = 1; j <= n; ++ j) { b[j] = a[j] % i; } sort(b + 1, b + n + 1); for (int j = 1; j <= n; ++ j){ sum += -(lower_bound(b + 1, b + n + 1, i - b[j]) - b - 1) + n; } } cout << ans - sum * 9; return 0; }