提交时间:2023-08-14 12:23:43
运行 ID: 98151
#include<bits/stdc++.h> #define int long long using namespace std; const int N = 2e5 + 5; int n, mx, mp, ans; int a[N], c[N][20]; inline int f(int x) { int res = 0; while(x) { res += x % 10; x /= 10; } return res; } signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for(int i = 1; i <= n; i++) cin >> a[i], mx = max(mx, a[i]); for(int i = 1; i <= n; i++) { int tmp = a[i], res = 0; while(tmp) { mp = max(mp, tmp % 10); c[i][++res] = tmp % 10; tmp /= 10; } } if(n <= 5000) { for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) ans += f(a[i] + a[j]); cout << ans; return 0; } if(mx <= 9) { int cnt[10]; memset(cnt, 0, sizeof(cnt)); for(int i = 1; i <= n; i++) cnt[a[i]]++; for(int i = 1; i <= n; i++) for(int j = 0; j <= 9; j++) ans += cnt[j] * f(a[i] + j); cout << ans; return 0; } if(mp <= 4) { for(int i = 1; i <= 16; i++) for(int j = 1; j <= n; j++) ans += c[j][i] * n * 2; cout << ans; return 0; } return 0; }