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

运行 ID: 98331

#include<bits/stdc++.h> #define int long long using namespace std; int n, mod, ans, sum; int a[200005], b[200005]; inline bool cmp(int x, int y) {return x % mod < y % mod;} signed main() { cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = 1; i <= n; i++) { int tmp = a[i]; while(tmp) { ans += tmp % 10; tmp /= 10; } } ans = 2 * n * ans; for(mod = 10; mod <= 1e15; mod *= 10) { sort(a + 1, a + n + 1, cmp); for(int i = 1; i <= n; i++) b[i] = a[i] % mod; for(int i = 1; i <= n; i++) sum += n + 1 - (lower_bound(b + 1, b + n + 1, mod - b[i]) - b); } cout << ans - sum * 9; return 0; }