提交时间:2023-08-14 11:56:54

运行 ID: 98053

#include <bits/stdc++.h> using namespace std; int n,f[17][10]; long long a[200005],ans=0,cnt=0,sum=0; int szh(long long x){ int y=0; while(x/10){ y+=x%10; x/=10; } y+=x; return y; } int main(){ cin >> n; if(n<=5000){ for(int i=1;i<=n;++i) cin >> a[i]; for(int i=1;i<=n;++i){ for(int j=1;j<=n;++j){ ans+=szh(a[i]+a[j]); } } cout << ans; return 0; } for(int i=1;i<=n;++i){ cin >> a[i]; int y=0,k=1; while(a[i]/10){ y+=a[i]%10; f[k++][a[i]%10]++; a[i]/=10; } f[k++][a[i]]++; y+=a[i]; ans+=y*n*2; } for(int i=1;i<=16;++i){ if(f[i][9]*(f[i][1]+f[i][2]+f[i][3]+f[i][4]+f[i][5]+f[i][6]+f[i][7]+f[i][8]+f[i][9])!=0) cnt+=f[i][9]*(f[i][1]+f[i][2]+f[i][3]+f[i][4]+f[i][5]+f[i][6]+f[i][7]+f[i][8]+f[i][9])*2-f[i][9]*f[i][9]; if(f[i][8]*(f[i][2]+f[i][3]+f[i][4]+f[i][5]+f[i][6]+f[i][7]+f[i][8])) cnt+=f[i][8]*(f[i][2]+f[i][3]+f[i][4]+f[i][5]+f[i][6]+f[i][7]+f[i][8])*2-f[i][8]*f[i][8]; if(f[i][7]*(f[i][3]+f[i][4]+f[i][5]+f[i][6]+f[i][7])) cnt+=f[i][7]*(f[i][3]+f[i][4]+f[i][5]+f[i][6]+f[i][7])*2-f[i][7]*f[i][7]; if(f[i][6]*(f[i][4]+f[i][5]+f[i][6])) cnt+=f[i][6]*(f[i][4]+f[i][5]+f[i][6])*2-f[i][6]*f[i][6]; if(f[i][5]) cnt+=f[i][5]*f[i][5]*2-f[i][5]*f[i][5]; } cout << ans-cnt*9; return 0; }