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

运行 ID: 98054

#include <bits/stdc++.h> using namespace std; int n; typedef long long ll; ll a[200005]; ll b[200005]; int main(){ cin>>n; bool aaa=1,bbb=1; long long mx=0; for(int i=1;i<=n;i++){ cin>>a[i]; mx=max(a[i],mx); if(a[i]>9) aaa=0; int tmp=a[i]; while(tmp&&bbb){ if(tmp%10>4) bbb=0; tmp=tmp/10; } } if(aaa){ ll ans=0,w[11]={0}; for(int i=1;i<=n;i++){ for(int j=0;j<=a[i];j++) w[j]++; } int s=0; for(int i=1;i<=n;i++){ s=s+(w[10-a[i]]); ans=ans+a[i]*n*2; // cout<<ans<<endl; } cout<<ans-s*9<<endl; } else if(bbb){ ll ans=0; for(int i=1;i<=n;i++){ ll tmp=a[i]; while(tmp){ ans=ans+2*n*(tmp%10); tmp=tmp/10; } } cout<<ans<<endl; } else if(n<=5000){ ll ans=0; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ ll si=a[i]+a[j],s=0; while(si>0){ s=s+si%10,si=si/10; } ans=ans+s; } } cout<<ans<<endl; } else{ ll cnt=0; while(mx) mx=mx/10,cnt++; ll ans1=0; for(int k=1;k<=cnt;k++){ ll ans=0,w[11]={0},nn=0,q=0; for(int i=1;i<=n;i++){ if(a[i]){ nn++;b[nn]=a[i]%10;a[i]=a[i]/10; } } for(int i=1;i<=nn;i++){ // cout<<b[i]<<" "; for(int j=0;j<=b[i];j++) w[j]++; } // cout<<endl; // cout<<nn<<endl; for(int i=1;i<=nn;i++){ q=q+(w[10-b[i]]); ans=ans+b[i]*nn*2; } // cout<<ans-q*9<<endl; ans1=ans1+ans-q*9; } cout<<ans1<<endl; } return 0; } /* 1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 14 16 21 113+106+120=339 */