提交时间:2023-08-14 15:42:20

运行 ID: 98347

#include<bits/stdc++.h> #define int long long using namespace std; int n, mod, ans, sum; int a[200005], b[200005]; 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) { int r = 0; for(int i = 1; i <= n; i++) b[i] = a[i] % mod; sort(b + 1, b + n + 1); for(int i = 1; i <= n; i++) { r = i; if(b[i] + b[1] >= mod) break; } for(int i = 1; i <= n; i++) { while(b[i] + b[r - 1] >= mod) r--; if(b[i] + b[r] >= mod) sum += (n - r + 1); } } cout << ans - sum * 9; return 0; }