提交时间:2023-08-14 12:24:14
运行 ID: 98160
#include<bits/stdc++.h> #define int long long using namespace std; const int N=2e5+5; int a[N],s[15],ans,n,add[N],m,che; signed main(){ ios::sync_with_stdio(0); cin.tie(0),cout.tie(0); cin>>n; for(int i=1;i<=n;++i){ cin>>a[i]; int x=0,y=a[i]; while(y!=0) x++,che=max(che,y%10),y/=10; m=max(m,x); } if(n<=5e3){ for(int i=1;i<=n;++i) for(int j=1;j<=n;++j){ int x=a[i]+a[j]; while(x>0){ ans+=x%10; x/=10; } } cout<<ans<<endl; return 0; } if(che<=4){ for(int i=1;i<=n;++i){ int x=a[i]; while(x>0) ans+=x%10,x/=10; } cout<<ans*n*2<<endl; return 0; } for(int i=1;i<=n;++i){ int x=a[i]%10; for(int j=x;j>=0;--j) s[x]++; } for(int i=0;i<=9;++i){ ans+=s[i]*i*n*2; ans-=s[10-i]*n*9; } cout<<ans<<endl; return 0; }