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

运行 ID: 98272

#include<bits/stdc++.h> #define int long long using namespace std; const int N = 2e5+2; int n,k = 1,ans,a[N],dig[17][N]; signed main() { scanf("%lld",&n); for(int i = 1;i <= n;i++) { scanf("%lld",&a[i]); for(int x = a[i],p = 1,ten = 1;x;x /= 10,p++,ten *= 10) { dig[p][i] = dig[p-1][i]+ten*(x%10); ans += 2*n*(x%10); if(x%10 > 4) k = 0; } } if(k) { printf("%lld",ans); return 0; } for(int d = 1,ten = 10;d <= 16;d++,ten *= 10) { for(int i = 1;i <= n;i++) if(!dig[d][i]) dig[d][i] = dig[d-1][i]; dig[d][0] = 0; sort(dig[d],dig[d]+n+1); for(int l = 0,r = n;l <= n;l++) { while(dig[d][r-1]+dig[d][l] >= ten) r--; if(dig[d][r]+dig[d][l] >= ten) ans -= (n-r+1)*9; } } printf("%lld",ans); return 0; }