提交时间:2023-08-14 12:28:43
运行 ID: 98217
#include<bits/stdc++.h> using namespace std; #define ll long long ll a[200005],b[200005]; int main(){ int n; scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%lld",&a[i]); if(n<=5003){ ll ans(0); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++){ ll x=a[i]+a[j]; ll res=0; while(x)res+=x%10,x/=10; ans+=res; } printf("%lld",ans); }else{ ll sum=0; for(int i=1;i<=n;i++){ ll x=a[i],res=0; while(x)res+=x%10,x/=10; b[i]=res; sum+=res; } ll ans(0); for(int i=1;i<=n;i++) ans+=n*b[i]+sum; printf("%lld",ans); } return 0; }