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

运行 ID: 98078

#include <bits/stdc++.h> using namespace std; long long ans,maxn,n,a[200005],maxnn,ws[200005],su[200005]; long long fj(long long x){ long long an=0,th=1; while(th<=x){ //th*=10; an+=(x/th)%10; maxnn=max(maxnn,(x/th)%10); th*=10; } return an; } int main(){ cin>>n; for(long long i=1;i<=n;i++){ cin>>a[i]; maxn=max(maxn,a[i]); su[i]=fj(a[i]); } //sbt2 ok if(maxn<=4){ long long qzh[200005]; for(long long i=1;i<=n;i++){ qzh[i]=qzh[i-1]+a[i]; } for(long long i=1;i<=n;i++)ans+=qzh[n]+n*a[i]; cout<<ans; }else if(maxn<10){ //sbt3 a<10且b<10 f(a+b)=a+b(a+b<10) f(a+b)=a+b-9(a+b>10) 只需要算出原来的和减去k个9 //ok long long num[20]; long long qzh[200005]; for(long long i=1;i<=n;i++){ qzh[i]=qzh[i-1]+a[i]; num[a[i]]++; } for(long long i=1;i<=n;i++){ ans+=qzh[n]+n*a[i]; for(long long j=9;j>=0;j--){ if(a[i]+j>=10)ans-=num[j]*9; } } cout<<ans; }else if(maxnn<=4){ //sbt4 ok long long qzh[200005]; for(long long i=1;i<=n;i++){ qzh[i]=qzh[i-1]+su[i]; } for(long long i=1;i<=n;i++)ans+=qzh[n]+n*su[i]; cout<<ans; }else{ for(long long i=1;i<=n;i++){ for(long long j=1;j<=n;j++){ ans+=fj(a[i]+a[j]); } } cout<<ans; } return 0; }