提交时间:2023-08-14 15:40:11
运行 ID: 98346
#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) { int r = 0; 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++) { 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; }