提交时间:2023-08-14 12:23:54
运行 ID: 98153
#include <bits/stdc++.h> using namespace std; #define rep(i, s, n) for (int i = (s); i <= (n); ++i) #define all_(s, n) (s) + 1, (s) + (n) + 1 typedef long long ll; int n; ll a[200005], b[200005]; ll sum = 0; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; rep(i, 1, n) { cin >> a[i]; ll x = a[i]; while (x != 0) { sum += x % 10; x /= 10; } } sum *= 2 * n; for (ll i = 10; i < 10000000000000000ll; i *= 10) { //10^15 rep(j, 1, n) { b[j] = a[j] % i; } sort(all_(b, n)); ll g = 0; rep(j, 1, n) { g += n - (lower_bound(all_(b, n), i - b[j]) - b) + 1; } sum -= g * 9; } cout << sum << endl; return 0; }