提交时间:2023-08-14 14:47:55
运行 ID: 98307
#include<bits/stdc++.h> using namespace std; #ifdef IAKIOI #define cin fin ifstream cin("in.txt"); #endif #define ll long long constexpr int N = 2e5 + 5; ll a[N], ans, b[N]; int n; int f(ll x) { int ans = 0; while (x) { ans += x % 10; x /= 10; } return ans; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i]; ans += 2 * n * f(a[i]); } for (ll p = 10; p <= 1000000000000000; p *= 10) { for (int i = 1; i <= n; ++i) b[i] = a[i] % p; stable_sort(b + 1, b + 1 + n, [](const ll &a, const ll &b) { return a < b; }); for (int i = 1; i <= n; ++i) { ans -= 9 * (n - (lower_bound(b + 1, b + 1 + n, p - b[i]) - b) + 1); } } cout << ans << endl; return 0; }