提交时间:2023-08-14 12:26:00

运行 ID: 98182

#include<bits/stdc++.h> #define N 200005 using namespace std; int n;long long a[N]; bool flg;int cnt[10],ans; inline int f(long long x){ int res(0); do{res+=x%10;} while(x/=10); return res; } int main(){ scanf("%d",&n); for(int i(1);i<=n;++i){ scanf("%lld",&a[i]); if(a[i]>9) flg=1; } if(n<=5000) for(int i(1);i<=n;++i) for(int j(1);j<=n;++j) ans+=f(a[i]+a[j]); else{ for(int i(1);i<=n;++i) ans+=2*n*f(a[i]); if(!flg){ for(int i(1);i<=n;++i) ++cnt[a[i]]; for(int i(1),res(0);i<=9;++i){ res+=cnt[10-i]; ans-=9*cnt[i]*res; } } } printf("%d\n",ans); return 0; }