提交时间:2023-08-14 15:21:43
运行 ID: 98336
#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++) { int l = 1, r = n, pos = n + 1; while(l <= r) { int mid = l + r >> 1; if(b[mid] < mod - b[i]) l = mid + 1; else r = (pos = mid) - 1; } sum += (n - pos + 1); } } cout << ans - sum * 9; return 0; }